Skip to content

Commit

Permalink
Try to fix yield from GC issues
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Jan 12, 2018
1 parent 420d11e commit cab0a81
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Zend/zend_generators.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,11 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */
zend_generator *root = generator->node.ptr.root, *next;
while (UNEXPECTED(root != generator)) {
next = zend_generator_get_child(&root->node, generator);
generator->node.ptr.root = next;
next->node.parent = NULL;
OBJ_RELEASE(&root->std);
root = next;
}
generator->node.parent = NULL;
}

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

leaf->node.ptr.root = root;
if (old_root) {
OBJ_RELEASE(&old_root->std);
}

return leaf->node.ptr.root = root;
return root;
}

static int zend_generator_get_next_delegated_value(zend_generator *generator) /* {{{ */
Expand Down

0 comments on commit cab0a81

Please sign in to comment.