Skip to content

Commit 07bb42b

Browse files
committed
Fix phpGH-17866: zend_mm_heap corrupted error after upgrading from 8.4.3 to 8.4.4
This regressed in phpGH-17592. The function is with its attributes HashTable* is copied in zend_get_closure_invoke_method() but its refcount is not increased. This caused a crash in the Symfony demo page.
1 parent 04a33a1 commit 07bb42b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-17866 (zend_mm_heap corrupted error after upgrading from 8.4.3 to 8.4.4)
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
#[Deprecated("xyzzy")]
8+
public function __invoke() {
9+
echo "In __invoke\n";
10+
}
11+
}
12+
13+
$foo = new Foo;
14+
$closure = Closure::fromCallable($foo);
15+
$test = $closure->__invoke(...);
16+
$test();
17+
18+
?>
19+
--EXPECTF--
20+
Deprecated: Method Foo::__invoke() is deprecated, xyzzy in %s on line %d
21+
In __invoke

Zend/zend_closures.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@ ZEND_API zend_function *zend_get_closure_invoke_method(zend_object *object) /* {
467467
ZEND_ACC_RETURN_REFERENCE | ZEND_ACC_VARIADIC | ZEND_ACC_HAS_RETURN_TYPE;
468468

469469
invoke->common = closure->func.common;
470+
471+
if (invoke->common.attributes) {
472+
GC_TRY_ADDREF(invoke->common.attributes);
473+
}
474+
470475
/* We return ZEND_INTERNAL_FUNCTION, but arg_info representation is the
471476
* same as for ZEND_USER_FUNCTION (uses zend_string* instead of char*).
472477
* This is not a problem, because ZEND_ACC_HAS_TYPE_HINTS is never set,

0 commit comments

Comments
 (0)