Skip to content

Commit 80504a6

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-19983: GC assertion failure with fibers, generators and destructors
2 parents f6f6fa9 + 6f6543e commit 80504a6

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

Zend/tests/fibers/gh19983.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
GH-19983 (GC Assertion Failure with fibers, generators and destructors)
3+
--SKIPIF--
4+
<?php if (PHP_INT_SIZE < 8) die("skip 64-bit only - fiber stacks exhaust 32-bit address space"); ?>
5+
--INI--
6+
memory_limit=128M
7+
--FILE--
8+
<?php
9+
class a
10+
{
11+
function __destruct()
12+
{
13+
$gen = (function () {
14+
$from = (function () {
15+
$cv = [new a];
16+
Fiber::suspend();
17+
})();
18+
yield from $from;
19+
})();
20+
$fiber = new Fiber(function () use ($gen, &$fiber) {
21+
$gen->current();
22+
});
23+
$fiber->start();
24+
}
25+
}
26+
new a;
27+
?>
28+
--EXPECTF--
29+
Fatal error: Allowed memory size of %d bytes exhausted%s

Zend/zend_gc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1953,13 +1953,15 @@ static zend_never_inline void gc_call_destructors_in_fiber(void)
19531953
GC_G(dtor_idx) = GC_FIRST_ROOT;
19541954
GC_G(dtor_end) = GC_G(first_unused);
19551955

1956+
zend_object *exception = NULL;
1957+
remember_prev_exception(&exception);
1958+
19561959
if (UNEXPECTED(!fiber)) {
19571960
fiber = gc_create_destructor_fiber();
19581961
} else {
19591962
zend_fiber_resume(fiber, NULL, NULL);
19601963
}
19611964

1962-
zend_object *exception = NULL;
19631965
remember_prev_exception(&exception);
19641966

19651967
for (;;) {

0 commit comments

Comments
 (0)