com php-src: Fixed bug #75396: NEWS Zend/tests/generators/bug75396.phpt Zend/zend_generators.c
| From: | Nikita Popov | Date: | Fri, 12 Jan 2018 20:27:23 +0000 |
| Subject: | com php-src: Fixed bug #75396: NEWS Zend/tests/generators/bug75396.phpt Zend/zend_generators.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-100864@lists.php.net to get a copy of this message | ||
Commit: 420d11e8caf8dc76e08984dfed3a4322295a1208
Author: Nikita Popov <nikita.ppv@gmail.com> Fri, 12 Jan 2018 21:24:04 +0100
Parents: 9e98e99a3a88f98d1377d5b2a43b7ad223d8a61f
Branches: PHP-7.1 PHP-7.2 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=420d11e8caf8dc76e08984dfed3a4322295a1208
Log:
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.
Bugs:
https://bugs.php.net/75396
Changed paths:
M NEWS
A Zend/tests/generators/bug75396.phpt
M Zend/zend_generators.c
Diff:
diff --git a/NEWS b/NEWS
index 4889178..23dccb0 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ PHP NEWS
. Fixed bug #75786 (segfault when using spread operator on generator passed
by reference). (Nikita)
. Fixed bug #75799 (arg of get_defined_functions is optional). (carusogabriel)
+ . Fixed bug #75396 (Exit inside generator finally results in fatal error).
+ (Nikita)
- Opcache:
. Fixed bug #75720 (File cache not populated after SHM runs full). (Dmitry)
diff --git a/Zend/tests/generators/bug75396.phpt b/Zend/tests/generators/bug75396.phpt
new file mode 100644
index 0000000..6d5abf5
--- /dev/null
+++ b/Zend/tests/generators/bug75396.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Bug #75396: Exit inside generator finally results in fatal error
+--FILE--
+<?php
+
+$gen = (function () {
+ yield 42;
+
+ try {
+ echo "Try\n";
+ exit("Exit\n");
+ } finally {
+ echo "Finally\n";
+ }
+})();
+
+$gen->send("x");
+
+?>
+--EXPECT--
+Try
+Exit
diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c
index 8ce6412..69fa17f 100644
--- a/Zend/zend_generators.c
+++ b/Zend/zend_generators.c
@@ -185,7 +185,8 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */
generator->node.parent = NULL;
}
- if (EXPECTED(!ex) || EXPECTED(!(ex->func->op_array.fn_flags &
ZEND_ACC_HAS_FINALLY_BLOCK))) {
+ if (EXPECTED(!ex) || EXPECTED(!(ex->func->op_array.fn_flags &
ZEND_ACC_HAS_FINALLY_BLOCK))
+ || CG(unclean_shutdown)) {
return;
}