From: Dmitry Stogov Date: Mon, 16 Jan 2006 10:12:36 +0000 (+0000) Subject: Fixed bug #36006 (Problem with $this in __destruct()) X-Git-Tag: php-5.1.3RC1~253 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b8360c376b5d66f61821765b96c9fda522b13fa5;p=php Fixed bug #36006 (Problem with $this in __destruct()) --- diff --git a/NEWS b/NEWS index 95a8902c89..78b216729b 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,7 @@ PHP NEWS - Fixed bug #36016 (realpath cache memleaks). (Dmitry, Nuno) - Fixed bug #36011 (Strict errormsg wrong for call_user_func() and the likes). (Marcus) +- Fixed bug #36006 (Problem with $this in __destruct()). (Dmitry) - Fixed bug #35998 (SplFileInfo::getPathname() returns unix style filenames in win32). (Marcus) diff --git a/Zend/tests/bug36006.phpt b/Zend/tests/bug36006.phpt new file mode 100755 index 0000000000..79f9897d13 --- /dev/null +++ b/Zend/tests/bug36006.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #36006 (Problem with $this in __destruct()) +--FILE-- +dad = null; /* no segfault if this is commented out */ + } +} + +class Dad extends Person { + public $son; + public function __construct() { + $this->son = new Person; + $this->son->dad = $this; /* no segfault if this is commented out */ + } + public function __destruct() { + $this->son = null; + parent::__destruct(); /* segfault here */ + } +} + +$o = new Dad; +unset($o); +echo "ok\n"; +?> +--EXPECT-- +ok diff --git a/Zend/zend_objects_API.c b/Zend/zend_objects_API.c index c47125de3d..0926c744c4 100644 --- a/Zend/zend_objects_API.c +++ b/Zend/zend_objects_API.c @@ -52,7 +52,9 @@ ZEND_API void zend_objects_store_call_destructors(zend_objects_store *objects TS if (!objects->object_buckets[i].destructor_called) { objects->object_buckets[i].destructor_called = 1; if (obj->dtor && obj->object) { + obj->refcount++; obj->dtor(obj->object, i TSRMLS_CC); + obj->refcount--; } } }