cvs: ZendEngine2 / zend_objects_API.c

From: Date: Wed, 03 Mar 2004 09:58:59 +0000
Subject: cvs: ZendEngine2 / zend_objects_API.c
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-2439@lists.php.net to get a copy of this message
andi Wed Mar 3 04:58:59 2004 EDT Modified files: /ZendEngine2 zend_objects_API.c Log: - Fix crash: <? class foo { function __destruct() { foreach ($this->x as $x); } } new foo(); echo 'OK'; ?> http://cvs.php.net/diff.php/ZendEngine2/zend_objects_API.c?r1=1.32&r2=1.33&ty=u Index: ZendEngine2/zend_objects_API.c diff -u ZendEngine2/zend_objects_API.c:1.32 ZendEngine2/zend_objects_API.c:1.33 --- ZendEngine2/zend_objects_API.c:1.32 Wed Feb 25 16:39:59 2004 +++ ZendEngine2/zend_objects_API.c Wed Mar 3 04:58:58 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_objects_API.c,v 1.32 2004/02/25 21:39:59 helly Exp $ */ +/* $Id: zend_objects_API.c,v 1.33 2004/03/03 09:58:58 andi Exp $ */ #include "zend.h" #include "zend_globals.h" @@ -127,20 +127,27 @@ zend_object_handle handle = Z_OBJ_HANDLE_P(zobject); struct _store_object *obj = &EG(objects_store).object_buckets[handle].bucket.obj; - if (--obj->refcount == 0) { + /* Make sure we hold a reference count during the destructor call + otherwise, when the destructor ends the storage might be freed + when the refcount reaches 0 a second time + */ + if (obj->refcount == 1) { if (!EG(objects_store).object_buckets[handle].destructor_called) { EG(objects_store).object_buckets[handle].destructor_called = 1; + if (obj->dtor) { obj->dtor(obj->object, handle TSRMLS_CC); } } - if (obj->refcount == 0) { + if (obj->refcount == 1) { if (obj->free_storage) { obj->free_storage(obj->object TSRMLS_CC); } ZEND_OBJECTS_STORE_ADD_TO_FREE_LIST(); } } + obj->refcount--; + #if ZEND_DEBUG_OBJECTS if (obj->refcount == 0) { fprintf(stderr, "Deallocated object id #%d\n", handle);

« previous php.zend-engine.cvs (#2439) next »