From 420d11e8caf8dc76e08984dfed3a4322295a1208 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 12 Jan 2018 21:24:04 +0100 Subject: [PATCH] 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. --- NEWS | 2 ++ Zend/tests/generators/bug75396.phpt | 22 ++++++++++++++++++++++ Zend/zend_generators.c | 3 ++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/generators/bug75396.phpt diff --git a/NEWS b/NEWS index 4889178d26..23dccb02ba 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 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-- +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; } -- 2.50.0