Skip to content

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

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

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

Conversation

@iliaal

@iliaal iliaal commented Jun 14, 2026

Copy link
Copy Markdown
Owner

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.
@iliaal

iliaal commented Jun 14, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as php#22311.

@iliaal iliaal closed this Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant