Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Zend/tests/generators/gh24430.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--TEST--
GH-24430 (SEGV in zend_generator_dtor_storage when GC closes cyclic generators in a Fiber)
--FILE--
<?php
$chunks = [];
for ($i = 0; $i < 32; $i++) {
$chunks[] = str_repeat('A', 4000);
}
unset($chunks);

function inner($id) {
try {
yield;
} finally {
if ($id === 3) {
throw new RuntimeException('from finally');
}
}
}

function wrapper($gen) {
try {
yield from $gen;
} catch (Exception $e) {
} finally {
}
}

(new Fiber(function () {
$holders = [];
for ($i = 0; $i < 6; $i++) {
$generator = wrapper(inner($i));
$generator->current();
$holder = new stdClass();
$holder->generator = $generator;
$holder->self = $holder;
$holders[] = $holder;
}
unset($holders);
try {
gc_collect_cycles();
} catch (RuntimeException $e) {
echo $e->getMessage(), "\n";
}
}))->start();

echo "Done\n";
?>
--EXPECT--
from finally
Done
3 changes: 2 additions & 1 deletion Zend/zend_generators.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */
const zend_op *old_opline_before_exception = NULL;
if (EG(exception)) {
if (EG(current_execute_data)
&& EG(current_execute_data)->opline
&& EG(current_execute_data)->func
&& ZEND_USER_CODE(EG(current_execute_data)->func->common.type)
&& EG(current_execute_data)->opline->opcode == ZEND_HANDLE_EXCEPTION) {
EG(current_execute_data)->opline = EG(opline_before_exception);
old_opline_before_exception = EG(opline_before_exception);
Expand Down
Loading