From 7ca414f5e77e78d49ac2a4c5f410735b64fbd854 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 16 Aug 2010 09:20:46 +0000 Subject: [PATCH] Bug #52361 (Throwing an exception in a destructor causes invalid catching) --- NEWS | 2 ++ Zend/tests/bug52361.phpt | 35 +++++++++++++++++++++++++++++++++++ Zend/zend_objects.c | 6 ++---- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 Zend/tests/bug52361.phpt diff --git a/NEWS b/NEWS index 36a0b2b935..2b76fc6c73 100644 --- a/NEWS +++ b/NEWS @@ -24,6 +24,8 @@ (Andrey) - Fixed bug #52413 (MySQLi/libmysql build failure on OS X, FreeBSD). (Andrey) - Fixed bug #52390 (mysqli_report() should be per-request setting). (Kalle) +- Fixed bug #52361 (Throwing an exception in a destructor causes invalid + catching). (Dmitry) - Fixed bug #52302 (mysqli_fetch_all does not work with MYSQLI_USE_RESULT). (Andrey) - Fixed bug #51610 (Using oci_connect causes PHP to take a long time to diff --git a/Zend/tests/bug52361.phpt b/Zend/tests/bug52361.phpt new file mode 100644 index 0000000000..3c2dffa63f --- /dev/null +++ b/Zend/tests/bug52361.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #52361 (Throwing an exception in a destructor causes invalid catching) +--FILE-- + +--EXPECTF-- +1. exception 'Exception' with message 'aaa' in %sbug52361.php:5 +Stack trace: +#0 %sbug52361.php(16): aaa->__destruct() +#1 %sbug52361.php(16): bbb() +#2 {main} +2. exception 'Exception' with message 'bbb' in %sbug52361.php:13 +Stack trace: +#0 %sbug52361.php(16): bbb() +#1 {main} + diff --git a/Zend/zend_objects.c b/Zend/zend_objects.c index ed9dc7c76c..9574f1d2cd 100644 --- a/Zend/zend_objects.c +++ b/Zend/zend_objects.c @@ -106,15 +106,13 @@ ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handl zend_error(E_ERROR, "Attempt to destruct pending exception"); } else { old_exception = EG(exception); - Z_ADDREF_P(old_exception); + EG(exception) = NULL; } } - zend_exception_save(TSRMLS_C); zend_call_method_with_0_params(&obj, object->ce, &destructor, ZEND_DESTRUCTOR_FUNC_NAME, NULL); - zend_exception_restore(TSRMLS_C); if (old_exception) { if (EG(exception)) { - zval_ptr_dtor(&old_exception); + zend_exception_set_previous(EG(exception), old_exception TSRMLS_CC); } else { EG(exception) = old_exception; } -- 2.40.0