Skip to content

Commit

Permalink
Fix GH-10496: Fibers must not be garbage collected while implicitly s…
Browse files Browse the repository at this point in the history
…uspended by resumption of another fiber
  • Loading branch information
bwoebi committed Feb 13, 2023
1 parent d721dcc commit 9501613
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Bug GH-10496 (Segfault when garbage collector is invoked inside of fiber)
Bug GH-10496 001 (Segfault when garbage collector is invoked inside of fiber)
--FILE--
<?php

Expand Down
26 changes: 26 additions & 0 deletions Zend/tests/fibers/gh10496-002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
Bug GH-10496 002 (Segfault when garbage collector is invoked inside of fiber)
--FILE--
<?php

function pollute_stack_and_suspend($a = 1, $b = 2, $c = 3) {
Fiber::suspend();
}

$f = new Fiber(function() use (&$f) {
pollute_stack_and_suspend();
(function() {
(function() {
(new Fiber(function() {
gc_collect_cycles();
echo "Success\n";
}))->start();
})();
})();
});
$f->start();
$f->resume();

?>
--EXPECT--
Success
2 changes: 1 addition & 1 deletion Zend/zend_fibers.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ static HashTable *zend_fiber_object_gc(zend_object *object, zval **table, int *n
zend_get_gc_buffer_add_zval(buf, &fiber->fci.function_name);
zend_get_gc_buffer_add_zval(buf, &fiber->result);

if (fiber->context.status != ZEND_FIBER_STATUS_SUSPENDED) {
if (fiber->context.status != ZEND_FIBER_STATUS_SUSPENDED || fiber->caller != NULL) {
zend_get_gc_buffer_use(buf, table, num);
return NULL;
}
Expand Down

0 comments on commit 9501613

Please sign in to comment.