Skip to content

Commit b398da2

Browse files
committed
Fix memory leaks
1 parent 3c9faab commit b398da2

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

Zend/tests/partial_application/constexpr_011.phpt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ PFA in constexpr: error during arg list evaluation
33
--FILE--
44
<?php
55

6-
function f($a = g(1, a: 2, ...)) {
6+
function f($a = g(strlen(?), e: strlen(?), a: strlen(?), ...)) {
77
}
88

9-
function g($a, $b) {
9+
function g($a, $b, $c, $d, $e) {
10+
}
11+
12+
function h($a = i(strlen(?), a: strlen(?), b: invalid(?), ...)) {
13+
}
14+
15+
function i(...$args) {
1016
}
1117

1218
try {
@@ -15,6 +21,13 @@ try {
1521
echo $e::class, ": ", $e->getMessage(), "\n";
1622
}
1723

24+
try {
25+
h();
26+
} catch (Error $e) {
27+
echo $e::class, ": ", $e->getMessage(), "\n";
28+
}
29+
1830
?>
1931
--EXPECT--
2032
Error: Named parameter $a overwrites previous argument
33+
Error: Call to undefined function invalid()

Zend/zend_ast.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -699,9 +699,6 @@ static zend_execute_data *zend_ast_evaluate_arg_list(
699699
arg_name = zend_ast_get_str(arg_ast->child[0]);
700700
arg = zend_handle_named_arg(&frame, arg_name, &arg_num, (void**)&cache_slot);
701701
if (!arg) {
702-
for (uint32_t j = 0; j < i; j++) {
703-
zval_ptr_dtor(ZEND_CALL_VAR_NUM(frame, j));
704-
}
705702
goto fail;
706703
}
707704
if (named_positions_ptr) {
@@ -728,9 +725,6 @@ static zend_execute_data *zend_ast_evaluate_arg_list(
728725
}
729726
} else {
730727
if (zend_ast_evaluate_ex(arg, arg_ast, scope, short_circuited_ptr, ctx) == FAILURE) {
731-
for (uint32_t j = 0; j < i; j++) {
732-
zval_ptr_dtor(ZEND_CALL_VAR_NUM(frame, j));
733-
}
734728
goto fail;
735729
}
736730
}
@@ -742,6 +736,12 @@ static zend_execute_data *zend_ast_evaluate_arg_list(
742736
return frame;
743737

744738
fail:
739+
for (uint32_t i = 0, num_args = ZEND_CALL_NUM_ARGS(frame); i < num_args; i++) {
740+
zval_ptr_dtor(ZEND_CALL_VAR_NUM(frame, i));
741+
}
742+
if (ZEND_CALL_INFO(frame) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) {
743+
zend_array_destroy(frame->extra_named_params);
744+
}
745745
zend_vm_stack_free_call_frame(frame);
746746
if (named_positions_ptr && *named_positions_ptr) {
747747
zend_array_destroy(*named_positions_ptr);

0 commit comments

Comments
 (0)