Skip to content

Fix leak when creating cycle in hook #18917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Zend/tests/gh18907.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
GH-18907: Leak when creating cycle inside hook
--FILE--
<?php

class Foo {
public $prop {
get {
$this->prop = $this;
return 1;
}
}
}

function test() {
var_dump((new Foo)->prop);
}

/* Call twice to test the ZEND_IS_PROPERTY_HOOK_SIMPLE_GET() path. */
test();
test();

?>
--EXPECT--
int(1)
int(1)
2 changes: 2 additions & 0 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,9 @@ static bool zend_call_get_hook(
return false;
}

GC_ADDREF(zobj);
zend_call_known_instance_method_with_0_params(get, zobj, rv);
OBJ_RELEASE(zobj);

return true;
}
Expand Down