Skip to content

Fix file descriptor leak when proc_open() descriptor setup fails#22311

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/proc-open-fd-leak
Open

Fix file descriptor leak when proc_open() descriptor setup fails#22311
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/proc-open-fd-leak

Conversation

@iliaal

@iliaal iliaal commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

When a descriptor spec entry fails to set up (unknown type, missing mode) after an earlier entry already opened a pipe or socket, proc_open() jumped to exit_fail without closing the descriptors it had already opened. The fds leak and repeated calls exhaust the process descriptor table; close_all_descriptors() ran only when the spawn itself failed. Close them at exit_fail and drop the now-redundant per-call close before each spawn-failure goto.

for ($i = 0; $i < 200; $i++) {
    @proc_open('true', [0 => ['pipe', 'r'], 1 => ['bogus']], $pipes);
}
// 400 fds leaked before the patch (2 per call)

When a descriptor spec entry fails to set up (unknown type, missing
mode) after an earlier entry already opened a pipe or socket, proc_open()
jumped to the failure path without closing the descriptors it had
already opened, leaking those fds; repeated calls exhaust the process
descriptor table. Close the opened descriptors on the failure path and
drop the now-redundant per-call close before each spawn-failure goto.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant