Skip to content

Fix arg zval leak in extract_callback_user_func#56

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:pr/userfunc-arg-leak
Open

Fix arg zval leak in extract_callback_user_func#56
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:pr/userfunc-arg-leak

Conversation

@iliaal
Copy link
Copy Markdown

@iliaal iliaal commented Jun 7, 2026

extract_callback_user_func ZVAL_STRINGL's each decoded chunk into arg but only freed it on the success path. Both early returns leaked one zend_string per chunk: zend_fcall_info_init() failure (reachable from userland by passing a non-callable as the callback) and zend_call_function() failure. zend_fcall_info_argn() takes its own reference via ZVAL_COPY, so the caller's arg always needs exactly one zval_ptr_dtor.

Release arg on every path; dtor retval only on the success path, where the engine has populated it.

The callback ZVAL_STRINGL's the chunk into `arg` but only released it on
the success path. Both early returns — when zend_fcall_info_init() fails
and when zend_call_function() fails — returned without dtoring `arg`,
leaking one zend_string per chunk. The init-failure path is reachable
from userland by passing a non-callable as the extract callback.

zend_fcall_info_argn() ZVAL_COPYs the argument into fci.params (its own
ref), so the original `arg` always needs exactly one zval_ptr_dtor.
Release it on every path; dtor `retval` only on success, where the
engine has actually written it.
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