From 3333380bf0da1aa744d19182cf6cef099681b4d6 Mon Sep 17 00:00:00 2001 From: Andi Gutmans Date: Tue, 2 Mar 2004 08:13:15 +0000 Subject: [PATCH] - Improve fix for protecting destructor's from exceptions. - I was killing the current exception completely which was wrong. --- Zend/zend_objects.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Zend/zend_objects.c b/Zend/zend_objects.c index bc4ac86f34..85f76302fc 100644 --- a/Zend/zend_objects.c +++ b/Zend/zend_objects.c @@ -32,6 +32,7 @@ ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handl if (destructor) { zval zobj, *obj = &zobj; + zval *old_exception; if (destructor->op_array.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) { if (destructor->op_array.fn_flags & ZEND_ACC_PRIVATE) { @@ -68,15 +69,17 @@ ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handl zobj.value.obj.handlers = &std_object_handlers; INIT_PZVAL(obj); - if (EG(exception)) { - zval_ptr_dtor(&EG(exception)); - EG(exception) = NULL; - } + /* Make sure that destructors are protected from previously thrown exceptions. + * For example, if an exception was thrown in a function and when the function's + * local variable destruction results in a destructor being called. + */ + old_exception = EG(exception); + EG(exception) = NULL; zend_call_method_with_0_params(&obj, object->ce, NULL, "__destruct", NULL); if (EG(exception)) { zval_ptr_dtor(&EG(exception)); - EG(exception) = NULL; } + EG(exception) = old_exception; } } -- 2.40.0