com php-src: Fixed bug #29368 (The destructor is called when an exception is thrown from the constructor).: NEWS UPGRADING Zend/tests/bug 29368_1.phpt
Zend/zend_vm_def.h Zend/ zend_vm_execute.h

From: Date: Wed, 13 Jul 2016 13:43:47 +0000
Subject: com php-src: Fixed bug #29368 (The destructor is called when an exception is thrown from the constructor).: NEWS UPGRADING Zend/tests/bug 29368_1.phpt
Zend/zend_vm_def.h Zend/ zend_vm_execute.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-92996@lists.php.net to get a copy of this message
Commit: afd3e39d6697e36d3b92cee5da911e4ea0de3901 Author: Dmitry Stogov <dmitry@zend.com> Wed, 13 Jul 2016 16:43:47 +0300 Parents: 3b8cb2119b33ed6b7701d78d32eed63593cf61ff Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=afd3e39d6697e36d3b92cee5da911e4ea0de3901 Log: Fixed bug #29368 (The destructor is called when an exception is thrown from the constructor). Bugs: https://bugs.php.net/29368 Changed paths: M NEWS M UPGRADING A Zend/tests/bug29368_1.phpt M Zend/zend_vm_def.h M Zend/zend_vm_execute.h Diff: diff --git a/NEWS b/NEWS index 91bba83..39261f4 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,8 @@ PHP NEWS . Added PHP to SAPI error severity mapping for logs. (Martin Vobruba) . Fixed bug #71911 (Unable to set --enable-debug on building extensions by phpize on Windows). (Yuji Uchiyama) + . Fixed bug #29368 (The destructor is called when an exception is thrown from + the constructor). (Dmitry) - COM: . Fixed bug #72569 (DOTNET/COM array parameters broke in PHP7). (Anatol) diff --git a/UPGRADING b/UPGRADING index 1759590..adb4741 100644 --- a/UPGRADING +++ b/UPGRADING @@ -47,6 +47,8 @@ PHP 7.1 UPGRADE NOTES syslog error levels. This brings finer differentiation in the error logs in contrary to the previous approach where all the errors are loggged with the notice level only. + . Don't call destructors of incompletely constructed objects, even if they + are kept referenced. See bug #29368 and Zend/tests/bug29368_1.phpt. - JSON: . The serialize_precision is used instead of precision when encoding double diff --git a/Zend/tests/bug29368_1.phpt b/Zend/tests/bug29368_1.phpt new file mode 100644 index 0000000..09cf334 --- /dev/null +++ b/Zend/tests/bug29368_1.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #29368.1 (The destructor is called when an exception is thrown from the constructor). +--FILE-- +<?php +function throwme($arg) +{ + throw new Exception; +} + +class foo { + function __construct() { + echo "Inside constructor\n"; + throwme($this); + } + + function __destruct() { + echo "Inside destructor\n"; + } +} + +try { + $bar = new foo; +} catch(Exception $exc) { + echo "Caught exception!\n"; +} +?> +--EXPECT-- +Inside constructor +Caught exception! diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index d10bd72..f93e89f 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -2500,9 +2500,7 @@ ZEND_VM_HELPER(zend_leave_helper, ANY, ANY) if (UNEXPECTED(EG(exception) != NULL) && (call_info & ZEND_CALL_CTOR)) { #endif GC_REFCOUNT(object)--; - if (GC_REFCOUNT(object) == 1) { - zend_object_store_ctor_failed(object); - } + zend_object_store_ctor_failed(object); } OBJ_RELEASE(object); } else if (UNEXPECTED(call_info & ZEND_CALL_CLOSURE)) { @@ -2537,9 +2535,7 @@ ZEND_VM_HELPER(zend_leave_helper, ANY, ANY) if (UNEXPECTED(EG(exception) != NULL) && (call_info & ZEND_CALL_CTOR)) { #endif GC_REFCOUNT(object)--; - if (GC_REFCOUNT(object) == 1) { - zend_object_store_ctor_failed(object); - } + zend_object_store_ctor_failed(object); } OBJ_RELEASE(object); } else if (UNEXPECTED(call_info & ZEND_CALL_CLOSURE)) { @@ -3803,9 +3799,7 @@ ZEND_VM_C_LABEL(fcall_end): if (UNEXPECTED(EG(exception) != NULL) && (ZEND_CALL_INFO(call) & ZEND_CALL_CTOR)) { #endif GC_REFCOUNT(object)--; - if (GC_REFCOUNT(object) == 1) { - zend_object_store_ctor_failed(object); - } + zend_object_store_ctor_failed(object); } OBJ_RELEASE(object); } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 37d8862..8574b24 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -492,9 +492,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_leave_helper_SPEC(ZEND_OPCODE_ if (UNEXPECTED(EG(exception) != NULL) && (call_info & ZEND_CALL_CTOR)) { #endif GC_REFCOUNT(object)--; - if (GC_REFCOUNT(object) == 1) { - zend_object_store_ctor_failed(object); - } + zend_object_store_ctor_failed(object); } OBJ_RELEASE(object); } else if (UNEXPECTED(call_info & ZEND_CALL_CLOSURE)) { @@ -529,9 +527,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_leave_helper_SPEC(ZEND_OPCODE_ if (UNEXPECTED(EG(exception) != NULL) && (call_info & ZEND_CALL_CTOR)) { #endif GC_REFCOUNT(object)--; - if (GC_REFCOUNT(object) == 1) { - zend_object_store_ctor_failed(object); - } + zend_object_store_ctor_failed(object); } OBJ_RELEASE(object); } else if (UNEXPECTED(call_info & ZEND_CALL_CLOSURE)) { @@ -1017,9 +1013,7 @@ fcall_end: if (UNEXPECTED(EG(exception) != NULL) && (ZEND_CALL_INFO(call) & ZEND_CALL_CTOR)) { #endif GC_REFCOUNT(object)--; - if (GC_REFCOUNT(object) == 1) { - zend_object_store_ctor_failed(object); - } + zend_object_store_ctor_failed(object); } OBJ_RELEASE(object); } @@ -1146,9 +1140,7 @@ fcall_end: if (UNEXPECTED(EG(exception) != NULL) && (ZEND_CALL_INFO(call) & ZEND_CALL_CTOR)) { #endif GC_REFCOUNT(object)--; - if (GC_REFCOUNT(object) == 1) { - zend_object_store_ctor_failed(object); - } + zend_object_store_ctor_failed(object); } OBJ_RELEASE(object); }

« previous php.cvs (#92996) next »