php-src/Zend/tests/bug69446.phpt
Arnaud Le Blanc 3c56af9902
Allow fiber switching during destructor execution
Fiber switching was disabled during destructor execution due to conflicts
with the garbage collector. This unfortunately introduces a function color
problem: destructors can not call functions that may switch Fibers.

In this change we update the GC so that Fiber switching during GC is safe. In
turn we allow Fiber switching during destrutor execution.

The GC executes destructors in a dedicated Fiber. If a destructor suspends, the
Fiber is owned by userland and a new dedicated Fiber is created to execute the
remaining destructors. Destructor suspension results in a resurection of the
object, which is handled as usual: The object is not considered garbage anymore,
but may be collected in a later run.

When the GC is executed in the main context (not in a Fiber), then destructors
are executed in the main context as well because there is no risk of conflicting
with GC in this case (main context can not suspend).

Fixes GH-11389
Closes GH-13460
2024-07-02 15:00:40 +02:00

35 lines
555 B
PHP

--TEST--
Bug #69446 (GC leak relating to removal of nested data after dtors run)
--INI--
zend.enable_gc = 1
--FILE--
<?php
$bar = NULL;
#[AllowDynamicProperties]
class bad {
public function __destruct() {
global $bar;
$bar = $this;
$bar->y = new stdClass;
}
}
$foo = new stdClass;
$foo->foo = $foo;
$foo->bad = new bad;
$foo->bad->x = new stdClass;
unset($foo);
gc_collect_cycles();
var_dump($bar);
?>
--EXPECTF--
object(bad)#%d (2) {
["x"]=>
object(stdClass)#%d (0) {
}
["y"]=>
object(stdClass)#%d (0) {
}
}