Skip to content

Commit 420d11e

Browse files
committed
Fixed bug #75396
Do not run finally blocks in generators on unclean shutdown (e.g. caused by exit). This is consistent with how finally blocks outside of generators behave.
1 parent 9e98e99 commit 420d11e

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ PHP NEWS
77
. Fixed bug #75786 (segfault when using spread operator on generator passed
88
by reference). (Nikita)
99
. Fixed bug #75799 (arg of get_defined_functions is optional). (carusogabriel)
10+
. Fixed bug #75396 (Exit inside generator finally results in fatal error).
11+
(Nikita)
1012

1113
- Opcache:
1214
. Fixed bug #75720 (File cache not populated after SHM runs full). (Dmitry)

Zend/tests/generators/bug75396.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #75396: Exit inside generator finally results in fatal error
3+
--FILE--
4+
<?php
5+
6+
$gen = (function () {
7+
yield 42;
8+
9+
try {
10+
echo "Try\n";
11+
exit("Exit\n");
12+
} finally {
13+
echo "Finally\n";
14+
}
15+
})();
16+
17+
$gen->send("x");
18+
19+
?>
20+
--EXPECT--
21+
Try
22+
Exit

Zend/zend_generators.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */
185185
generator->node.parent = NULL;
186186
}
187187

188-
if (EXPECTED(!ex) || EXPECTED(!(ex->func->op_array.fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK))) {
188+
if (EXPECTED(!ex) || EXPECTED(!(ex->func->op_array.fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK))
189+
|| CG(unclean_shutdown)) {
189190
return;
190191
}
191192

0 commit comments

Comments
 (0)