Skip to content

Commit 500ba8b

Browse files
committed
Handle reallocated root buffer during GC destroy phase (v2)
We no longer protect GC during the destroy phase, so we need to deal with buffer reallocation. Note that the implementation of spl_SplObjectStorage_free_storage will call the destructor of SplObjectStorage, and free the instance properties, which I think is what caused the root buffer to be reallocated. (`current` is a pointer for an index within the root buffer?) This fixes bug #78811 for me. Closes GH-4935
1 parent e7e1545 commit 500ba8b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Zend/zend_gc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1551,6 +1551,8 @@ ZEND_API int zend_gc_collect_cycles(void)
15511551
EG(objects_store).object_buckets[obj->handle] = SET_OBJ_INVALID(obj);
15521552
GC_TYPE_INFO(obj) = IS_NULL |
15531553
(GC_TYPE_INFO(obj) & ~GC_TYPE_MASK);
1554+
/* Modify current before calling free_obj (bug #78811: free_obj() can cause the root buffer (with current) to be reallocated.) */
1555+
current->ref = GC_MAKE_GARBAGE(((char*)obj) - obj->handlers->offset);
15541556
if (!(OBJ_FLAGS(obj) & IS_OBJ_FREE_CALLED)) {
15551557
GC_ADD_FLAGS(obj, IS_OBJ_FREE_CALLED);
15561558
GC_ADDREF(obj);
@@ -1559,7 +1561,6 @@ ZEND_API int zend_gc_collect_cycles(void)
15591561
}
15601562

15611563
ZEND_OBJECTS_STORE_ADD_TO_FREE_LIST(obj->handle);
1562-
current->ref = GC_MAKE_GARBAGE(((char*)obj) - obj->handlers->offset);
15631564
} else if (GC_TYPE(p) == IS_ARRAY) {
15641565
zend_array *arr = (zend_array*)p;
15651566

0 commit comments

Comments
 (0)