Skip to content

Free unbound arguments when partial application construction throws#22788

Merged
iliaal merged 1 commit into
php:masterfrom
iliaal:fix/pfa-partial-arg-leak
Jul 17, 2026
Merged

Free unbound arguments when partial application construction throws#22788
iliaal merged 1 commit into
php:masterfrom
iliaal:fix/pfa-partial-arg-leak

Conversation

@iliaal

@iliaal iliaal commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

The ZEND_CALLABLE_CONVERT_PARTIAL handler relies on zp_bind() to move each pre-bound argument into the partial closure and never frees positional arguments itself. When construction throws before an argument is moved, either a NULL op_array (argument count error, unknown default value, forbidden dynamic call) or a bound-argument type error, the unmoved arguments were owned by nobody and leaked. A try/catch loop over a failing partial with refcounted arguments leaks within the request until memory_limit. Free the arguments that were not moved at each throwing path.

Reproducer, definitely-lost blocks under valgrind before the fix, clean after:

php -r 'function f(int $a, $b, $c){} for ($i=0;$i<200;$i++){ try { f([1], new stdClass, ?); } catch (\Throwable $e) {} }'

The ZEND_CALLABLE_CONVERT_PARTIAL handler relies on zp_bind() to move
each pre-bound argument into the partial and never frees positional
arguments itself. When construction throws before an argument is moved,
a NULL op_array from zp_get_op_array() or a bound-argument type error,
the unmoved arguments were owned by nobody and leaked. Free the
arguments that were not moved at each throwing path.

@arnaud-lb arnaud-lb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@iliaal
iliaal merged commit b7c524a into php:master Jul 17, 2026
18 checks passed
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