Skip to content

Commit cab0a81

Browse files
committed
Try to fix yield from GC issues
Make sure we always update root and parent references before releasing the old root object. This fixes some crashes under aggressive cycle collection, so hopefully this will also fix bug #75351.
1 parent 420d11e commit cab0a81

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Zend/zend_generators.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,11 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */
179179
zend_generator *root = generator->node.ptr.root, *next;
180180
while (UNEXPECTED(root != generator)) {
181181
next = zend_generator_get_child(&root->node, generator);
182+
generator->node.ptr.root = next;
183+
next->node.parent = NULL;
182184
OBJ_RELEASE(&root->std);
183185
root = next;
184186
}
185-
generator->node.parent = NULL;
186187
}
187188

188189
if (EXPECTED(!ex) || EXPECTED(!(ex->func->op_array.fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK))
@@ -664,11 +665,12 @@ ZEND_API zend_generator *zend_generator_update_current(zend_generator *generator
664665
}
665666
}
666667

668+
leaf->node.ptr.root = root;
667669
if (old_root) {
668670
OBJ_RELEASE(&old_root->std);
669671
}
670672

671-
return leaf->node.ptr.root = root;
673+
return root;
672674
}
673675

674676
static int zend_generator_get_next_delegated_value(zend_generator *generator) /* {{{ */

0 commit comments

Comments
 (0)