Skip to content

Fix memory leak in phpdbg calling registered function #17635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sapi/phpdbg/phpdbg_lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ INPUT ("\\"[#"']|["]("\\\\"|"\\"["]|[^\n\000"])*["]|[']("\\"[']|"\\\\"|[^\

<NORMAL>{GENERIC_ID} {
phpdbg_init_param(yylval, STR_PARAM);
yylval->str = estrndup(yytext, yyleng - unescape_string(yytext));
yylval->len = yyleng;
size_t len = yyleng - unescape_string(yytext);
yylval->str = estrndup(yytext, len);
yylval->len = len;
return T_ID;
}

Expand Down
3 changes: 3 additions & 0 deletions sapi/phpdbg/phpdbg_prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */

zval_ptr_dtor_str(&fci.function_name);
efree(lc_name);
if (fci.named_params) {
zend_array_destroy(fci.named_params);
}

return SUCCESS;
}
Expand Down
24 changes: 24 additions & 0 deletions sapi/phpdbg/tests/register_function_leak.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
registering a function and calling it leaks arguments memory
--FILE--
<?php
echo "Done\n";
?>
--PHPDBG--
register var_dump
var_dump "a" "b"
register flush
flush
r
q
--EXPECTF--
[Successful compilation of %s]
prompt> [Registered var_dump]
prompt> string(1) "a"
string(1) "b"

prompt> [Registered flush]
prompt>
prompt> Done
[Script ended normally]
prompt>
Loading