Skip to content

Comments

ext/pcntl: Fix cpuset leak in pcntl_setcpuaffinity on out-of-range CPU ID#21268

Open
devnexen wants to merge 1 commit intophp:PHP-8.4from
devnexen:pcntl_cpu_fix
Open

ext/pcntl: Fix cpuset leak in pcntl_setcpuaffinity on out-of-range CPU ID#21268
devnexen wants to merge 1 commit intophp:PHP-8.4from
devnexen:pcntl_cpu_fix

Conversation

@devnexen
Copy link
Member

Add missing PCNTL_CPU_DESTROY(mask) call before RETURN_THROWS() when the cpu id is out of range, matching the cleanup on other error paths.

…U ID

Add missing PCNTL_CPU_DESTROY(mask) call before RETURN_THROWS() when
the cpu id is out of range, matching the cleanup on other error paths.
@devnexen devnexen changed the title Fix cpuset leak in pcntl_setcpuaffinity on out-of-range CPU ID ext/pcntl: Fix cpuset leak in pcntl_setcpuaffinity on out-of-range CPU ID Feb 21, 2026
@devnexen devnexen marked this pull request as ready for review February 21, 2026 04:50
Copy link
Member

@ndossche ndossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find. Do you think this can easily be tested?

@devnexen
Copy link
Member Author

The error path is already covered by the existing test in ext/pcntl/tests/pcntl_cpuaffinity.phpt (the PHP_INT_MAX case). However, the fix itself addresses a C-level resource leak (cpuset_destroy /
pset_destroy) that only manifests on NetBSD and Solaris (ci not merged for this one yet I think) — on Linux/FreeBSD PCNTL_CPU_DESTROY is a no-op. So the leak isn't directly observable from a PHP-level test; it would only show up under valgrind or on
the affected platforms.

@ndossche
Copy link
Member

Ack

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.

2 participants