Skip to content

Commit 6c5bed3

Browse files
committed
Fix missing addref for __unset
Fixes GH-21603 Closes GH-21604
1 parent 72c12ea commit 6c5bed3

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ PHP NEWS
1010
. Fixed bug GH-21605 (Missing addref for Countable::count()). (ilutov)
1111
. Fixed bug GH-21699 (Assertion failure in shutdown_executor when resolving
1212
self::/parent::/static:: callables if the error handler throws). (macoaure)
13+
. Fixed bug GH-21603 (Missing addref for __unset). (ilutov)
1314

1415
- Curl:
1516
. Add support for brotli and zstd on Windows. (Shivam Mathur)

Zend/tests/gh21603.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-21603: Missing addref for __unset
3+
--CREDITS--
4+
cnwangjihe
5+
--FILE--
6+
<?php
7+
8+
class C {
9+
public function __unset($name) {
10+
global $c;
11+
$c = null;
12+
var_dump($this);
13+
}
14+
}
15+
16+
$c = new C;
17+
unset($c->prop);
18+
19+
?>
20+
--EXPECTF--
21+
object(C)#%d (0) {
22+
}

Zend/zend_object_handlers.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,9 +1653,11 @@ ZEND_API void zend_std_unset_property(zend_object *zobj, zend_string *name, void
16531653
}
16541654
if (!((*guard) & IN_UNSET)) {
16551655
/* have unsetter - try with it! */
1656+
GC_ADDREF(zobj);
16561657
(*guard) |= IN_UNSET; /* prevent circular unsetting */
16571658
zend_std_call_unsetter(zobj, name);
16581659
(*guard) &= ~IN_UNSET;
1660+
OBJ_RELEASE(zobj);
16591661
return;
16601662
} else if (UNEXPECTED(IS_WRONG_PROPERTY_OFFSET(property_offset))) {
16611663
/* Trigger the correct error */

0 commit comments

Comments
 (0)