Skip to content

Commit ef10339

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix memory leak in phpdbg calling registered function Partially fix GH-17387
2 parents 6e84c41 + 29bafa6 commit ef10339

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

sapi/phpdbg/phpdbg_lexer.l

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ INPUT ("\\"[#"']|["]("\\\\"|"\\"["]|[^\n\000"])*["]|[']("\\"[']|"\\\\"|[^\
160160
161161
<NORMAL>{GENERIC_ID} {
162162
phpdbg_init_param(yylval, STR_PARAM);
163-
yylval->str = estrndup(yytext, yyleng - unescape_string(yytext));
164-
yylval->len = yyleng;
163+
size_t len = yyleng - unescape_string(yytext);
164+
yylval->str = estrndup(yytext, len);
165+
yylval->len = len;
165166
return T_ID;
166167
}
167168

sapi/phpdbg/phpdbg_prompt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */
168168
zend_call_known_function(user_fn, NULL, NULL, NULL, 0, NULL, params_ht);
169169
phpdbg_out("\n");
170170

171+
if (params_ht) {
172+
zend_array_destroy(params_ht);
173+
}
174+
171175
return SUCCESS;
172176
}
173177
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
registering a function and calling it leaks arguments memory
3+
--FILE--
4+
<?php
5+
echo "Done\n";
6+
?>
7+
--PHPDBG--
8+
register var_dump
9+
var_dump "a" "b"
10+
register flush
11+
flush
12+
r
13+
q
14+
--EXPECTF--
15+
[Successful compilation of %s]
16+
prompt> [Registered var_dump]
17+
prompt> string(1) "a"
18+
string(1) "b"
19+
20+
prompt> [Registered flush]
21+
prompt>
22+
prompt> Done
23+
[Script ended normally]
24+
prompt>

0 commit comments

Comments
 (0)