summaryrefslogtreecommitdiff
path: root/Zend
diff options
context:
space:
mode:
Diffstat (limited to 'Zend')
-rw-r--r--Zend/tests/bug47771.phpt30
-rw-r--r--Zend/zend_vm_def.h9
-rw-r--r--Zend/zend_vm_execute.h9
3 files changed, 44 insertions, 4 deletions
diff --git a/Zend/tests/bug47771.phpt b/Zend/tests/bug47771.phpt
new file mode 100644
index 0000000000..a17fcf3b58
--- /dev/null
+++ b/Zend/tests/bug47771.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Bug #47771 (Exception during object construction from arg call calls object's destructor)
+--FILE--
+<?php
+function throw_exc() {
+ throw new Exception('TEST_EXCEPTION');
+}
+
+class Test {
+
+ public function __construct() {
+ echo 'Constr' ."\n";
+ }
+
+ public function __destruct() {
+ echo 'Destr' ."\n";
+ }
+
+}
+
+try {
+
+ $T =new Test(throw_exc());
+
+} catch( Exception $e) {
+ echo 'Exception: ' . $e->getMessage() . "\n";
+}
+?>
+--EXPECT--
+Exception: TEST_EXCEPTION
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index 14c5029fff..24c51f39f6 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -4286,8 +4286,13 @@ ZEND_VM_HANDLER(149, ZEND_HANDLE_EXCEPTION, ANY, ANY)
while (EX(fbc)) {
EX(called_scope) = (zend_class_entry*)zend_ptr_stack_pop(&EG(arg_types_stack));
if (EX(object)) {
- if (IS_CTOR_USED(EX(called_scope))) {
- Z_DELREF_P(EX(object));
+ if (IS_CTOR_CALL(EX(called_scope))) {
+ if (IS_CTOR_USED(EX(called_scope))) {
+ Z_DELREF_P(EX(object));
+ }
+ if (Z_REFCOUNT_P(EX(object)) == 1) {
+ zend_object_store_ctor_failed(EX(object) TSRMLS_CC);
+ }
}
zval_ptr_dtor(&EX(object));
}
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index 11bd18b9a5..fe902cb244 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -625,8 +625,13 @@ static int ZEND_FASTCALL ZEND_HANDLE_EXCEPTION_SPEC_HANDLER(ZEND_OPCODE_HANDLER
while (EX(fbc)) {
EX(called_scope) = (zend_class_entry*)zend_ptr_stack_pop(&EG(arg_types_stack));
if (EX(object)) {
- if (IS_CTOR_USED(EX(called_scope))) {
- Z_DELREF_P(EX(object));
+ if (IS_CTOR_CALL(EX(called_scope))) {
+ if (IS_CTOR_USED(EX(called_scope))) {
+ Z_DELREF_P(EX(object));
+ }
+ if (Z_REFCOUNT_P(EX(object)) == 1) {
+ zend_object_store_ctor_failed(EX(object) TSRMLS_CC);
+ }
}
zval_ptr_dtor(&EX(object));
}