From c35fc7889025816f76d142b43a3a2452a59869d5 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 9 Dec 2010 16:38:37 +0000 Subject: [PATCH] Fixed bug #53511 (Exceptions are lost in case an exception is thrown in catch operator) --- Zend/tests/bug53511.phpt | 33 ++++++++++++++++++++++++++++++++ Zend/zend_vm_def.h | 2 +- Zend/zend_vm_execute.h | 2 +- ext/spl/tests/iterator_041b.phpt | 13 +++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 Zend/tests/bug53511.phpt diff --git a/Zend/tests/bug53511.phpt b/Zend/tests/bug53511.phpt new file mode 100644 index 0000000000..88f0cbe8f4 --- /dev/null +++ b/Zend/tests/bug53511.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #53511 (Exceptions are lost in case an exception is thrown in catch operator) +--FILE-- +getMessage()."\n"; + } +} + +test(); +echo "bug\n"; +--EXPECTF-- +Fatal error: Uncaught exception 'Exception' with message 'ops 2' in %sbug53511.php:11 +Stack trace: +#0 %sbug53511.php(17): test() +#1 {main} + +Next exception 'Exception' with message 'ops 1' in %sbug53511.php:4 +Stack trace: +#0 %sbug53511.php(12): Foo->__destruct() +#1 %sbug53511.php(17): test() +#2 {main} + thrown in %sbug53511.php on line 4 diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 005c92b532..bbb8052174 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -2918,7 +2918,7 @@ ZEND_VM_HANDLER(107, ZEND_CATCH, CONST, CV) &EG(exception), sizeof(zval *), (void**)&EX_CV(opline->op2.var)); } if (UNEXPECTED(EG(exception) != exception)) { - EG(exception) = NULL; + Z_ADDREF_P(EG(exception)); HANDLE_EXCEPTION(); } else { EG(exception) = NULL; diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index b6a1179b25..42425d9cd6 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -5843,7 +5843,7 @@ static int ZEND_FASTCALL ZEND_CATCH_SPEC_CONST_CV_HANDLER(ZEND_OPCODE_HANDLER_A &EG(exception), sizeof(zval *), (void**)&EX_CV(opline->op2.var)); } if (UNEXPECTED(EG(exception) != exception)) { - EG(exception) = NULL; + Z_ADDREF_P(EG(exception)); HANDLE_EXCEPTION(); } else { EG(exception) = NULL; diff --git a/ext/spl/tests/iterator_041b.phpt b/ext/spl/tests/iterator_041b.phpt index e166f6bdce..e7ea8b8008 100755 --- a/ext/spl/tests/iterator_041b.phpt +++ b/ext/spl/tests/iterator_041b.phpt @@ -82,6 +82,10 @@ class MyArrayIterator extends ArrayIterator { self::$fail++; } + try { + $e = null; + } catch (Exception $e) { + } } } } @@ -101,10 +105,19 @@ State 3: valid() State 4: current() State 5: key() State 6: next() +State 7: __destruct() +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} ===iterator_count=== State 0: __construct() State 1: __construct() State 2: rewind() State 3: valid() State 6: next() +State 7: __destruct() +int(2) ===DONE=== -- 2.40.0