php-src/Zend/tests/gh15108-005.phpt
Arnaud Le Blanc 99e0d3fe09
Fix destruction of generator running in fibers during shutdown (#15158)
The destructor of generators is a no-op when the generator is running in a fiber,
because the fiber may resume the generator. Normally the destructor
is not called in this case, but this can happen during shutdown.

We detect that a generator is running in a fiber with the
ZEND_GENERATOR_IN_FIBER flag.

This change fixes two cases not handled by this mechanism:

- The ZEND_GENERATOR_IN_FIBER flag was not added when resuming a "yield from $nonGenerator"

- When a generator that is running in a fiber has multiple children (aka multiple generators yielding from it), all of them could be considered to also run in a fiber (only one actually is), and could leak if not destroyed before shutdown.
2024-07-30 14:53:19 +02:00

46 lines
708 B
PHP

--TEST--
GH-15108 005: Segfault with delegated generator in suspended fiber
--FILE--
<?php
class It implements \IteratorAggregate
{
public function getIterator(): \Generator
{
yield 'foo';
Fiber::suspend();
var_dump("not executed");
}
}
function f() {
yield from new It();
}
function g() {
yield from f();
}
function h() {
/* g() is an intermediate node and will not be marked with IN_FIBER */
yield from g();
}
$iterable = h();
var_dump($iterable->current());
$fiber = new Fiber(function () use ($iterable) {
$iterable->next();
var_dump("not executed");
});
$ref = $fiber;
$fiber->start();
?>
==DONE==
--EXPECT--
string(3) "foo"
==DONE==