Skip to content

Commit 819064a

Browse files
committed
Fix leak when creating cycle in hook
This is necessary because the VM frees operands with the nogc variants. We cannot just call gc_possible_root() because the object may no longer exist at that point. Fixes GH-18907
1 parent 2577e3a commit 819064a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Zend/tests/gh18907.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-18907: Leak when creating cycle inside hook
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
public $prop {
8+
get {
9+
$this->prop = $this;
10+
return 1;
11+
}
12+
}
13+
}
14+
15+
function test() {
16+
var_dump((new Foo)->prop);
17+
}
18+
19+
/* Call twice to test the ZEND_IS_PROPERTY_HOOK_SIMPLE_GET() path. */
20+
test();
21+
test();
22+
23+
?>
24+
--EXPECT--
25+
int(1)
26+
int(1)

Zend/zend_object_handlers.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,9 @@ static bool zend_call_get_hook(
719719
return false;
720720
}
721721

722+
GC_ADDREF(zobj);
722723
zend_call_known_instance_method_with_0_params(get, zobj, rv);
724+
OBJ_RELEASE(zobj);
723725

724726
return true;
725727
}

0 commit comments

Comments
 (0)