Skip to content

Commit dfcc043

Browse files
committed
Fix leak of duplicate named argument in new in initializer
Closes GH-25059
1 parent 5300734 commit dfcc043

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ PHP NEWS
4242
abstract on properties. (Jorg Sowa)
4343
. Fixed AST export of readonly anonymous classes dropping the readonly
4444
modifier. (Jorg Sowa)
45+
. Fixed memory leak of a duplicate named argument in new in initializer.
46+
(Jorg Sowa)
4547

4648
- CLI:
4749
. Fixed bug GH-24697 (PHP_HTTP_PARSER_STRICT build option doesn't work).
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Duplicate named param in new in const expr does not leak the argument
3+
--FILE--
4+
<?php
5+
6+
class D {}
7+
class C {
8+
public function __construct(public $a) {}
9+
}
10+
11+
function f($x = new C(a: new D, a: new D)) {}
12+
13+
try {
14+
f();
15+
} catch (Error $e) {
16+
echo $e::class, ": ", $e->getMessage(), "\n";
17+
}
18+
19+
?>
20+
--EXPECT--
21+
Error: Named parameter $a overwrites previous argument

‎Zend/zend_ast.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_inner(
942942
zend_throw_error(NULL,
943943
"Named parameter $%s overwrites previous argument",
944944
ZSTR_VAL(name));
945+
zval_ptr_dtor(&arg);
945946
zend_array_destroy(args);
946947
zval_ptr_dtor(result);
947948
return FAILURE;

0 commit comments

Comments
 (0)