]> granicus.if.org Git - php/commitdiff
- Improve fix for protecting destructor's from exceptions.
authorAndi Gutmans <andi@php.net>
Tue, 2 Mar 2004 08:13:15 +0000 (08:13 +0000)
committerAndi Gutmans <andi@php.net>
Tue, 2 Mar 2004 08:13:15 +0000 (08:13 +0000)
- I was killing the current exception completely which was wrong.

Zend/zend_objects.c

index bc4ac86f341e3cfcecb4ed70afe3e36baf0e91be..85f76302fc4ac02d7e3f3822c4d440f32f193684 100644 (file)
@@ -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;
        }
 }