]> granicus.if.org Git - php/commitdiff
Fixed bug #47771 (Exception during object construction from arg call calls object...
authorDmitry Stogov <dmitry@php.net>
Thu, 26 Mar 2009 10:17:47 +0000 (10:17 +0000)
committerDmitry Stogov <dmitry@php.net>
Thu, 26 Mar 2009 10:17:47 +0000 (10:17 +0000)
Zend/tests/bug47771.phpt [new file with mode: 0644]
Zend/zend_vm_def.h
Zend/zend_vm_execute.h

diff --git a/Zend/tests/bug47771.phpt b/Zend/tests/bug47771.phpt
new file mode 100644 (file)
index 0000000..a17fcf3
--- /dev/null
@@ -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
index ee2681ddaa2401b9f763d66d5f5fb91d2e2867f6..7d674326ba974ac88ae587dd251c4201d77e2a24 100644 (file)
@@ -4472,8 +4472,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));
                }
index 56194b68e1066c59697b67ebe1fe56057d03bc65..c39d5449dc8fed09ed8f9d273b7daaffa5db354d 100644 (file)
@@ -633,8 +633,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));
                }