From 1d896d01ab7bcd0c4a3c2cced799796dfcb469e4 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Mon, 21 Oct 2024 17:00:26 +0200 Subject: [PATCH] Fix crash when yielding from generators are destroyed I.e. destroyed without clean finish. Signed-off-by: Bob Weinand --- zend_abstract_interface/interceptor/php8/interceptor.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zend_abstract_interface/interceptor/php8/interceptor.c b/zend_abstract_interface/interceptor/php8/interceptor.c index c6ec86a7ac..699a475c27 100644 --- a/zend_abstract_interface/interceptor/php8/interceptor.c +++ b/zend_abstract_interface/interceptor/php8/interceptor.c @@ -397,14 +397,14 @@ static void zai_interceptor_observer_generator_yield(zend_execute_data *ex, zval static void zai_interceptor_handle_ended_generator(zend_generator *generator, zend_execute_data *ex, zval *retval, zai_frame_memory *frame_memory) { if (frame_memory->implicit) { - zai_install_address genaddr = zai_hook_install_address_user(&generator->execute_data->func->op_array); + zai_install_address genaddr = zai_hook_install_address_user(&ex->func->op_array); zval *count = zend_hash_index_find(&zai_interceptor_implicit_generators, genaddr); if (count && !--Z_LVAL_P(count)) { zend_hash_index_del(&zai_interceptor_implicit_generators, genaddr); if (!zend_hash_index_exists(&zai_hook_resolved, genaddr)) { zend_observer_fcall_end_handler next_end_handler = NULL; - zai_interceptor_replace_observer(generator->execute_data->func, true, &next_end_handler); - if (UNEXPECTED(next_end_handler)) { + zai_interceptor_replace_observer(ex->func, true, &next_end_handler); + if (UNEXPECTED(next_end_handler) && generator->execute_data == ex /* Not equal within dtor */) { next_end_handler(ex, retval); } }