diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2018-01-12 21:24:04 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2018-01-12 21:27:23 +0100 |
commit | 420d11e8caf8dc76e08984dfed3a4322295a1208 (patch) | |
tree | 542f32597801f11684e9d8104b01ca13e0747fe0 | |
parent | 9e98e99a3a88f98d1377d5b2a43b7ad223d8a61f (diff) | |
download | php-git-420d11e8caf8dc76e08984dfed3a4322295a1208.tar.gz |
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.
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | Zend/tests/generators/bug75396.phpt | 22 | ||||
-rw-r--r-- | Zend/zend_generators.c | 3 |
3 files changed, 26 insertions, 1 deletions
@@ -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 0000000000..6d5abf518f --- /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 8ce641286d..69fa17f74f 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; } |