]> 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:30 +0000 (10:17 +0000)
committerDmitry Stogov <dmitry@php.net>
Thu, 26 Mar 2009 10:17:30 +0000 (10:17 +0000)
NEWS
Zend/tests/bug47771.phpt [new file with mode: 0644]
Zend/zend_vm_def.h
Zend/zend_vm_execute.h

diff --git a/NEWS b/NEWS
index d8bde6405f8c349d60a277661cbc5c7cd9b80539..096a6e8b8b8c308b6bd050a26f75321b968dc230 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,8 @@ PHP                                                                        NEWS
 ?? ??? 200?, PHP 5.3.0 RC 2
 - Fixed bug #47779 (Wrong value for SIG_UNBLOCK and SIG_SETMASK constants).
   (Matteo)
+- Fixed bug #47771 (Exception during object construction from arg call calls
+  object's destructor). (Dmitry)
 - Fixed bug #47699 (autoload and late static binding). (Dmitry)
 - Fixed bug #47038 (Memory leak in include). (Dmitry)
 - Fixed bug #44409 (PDO::FETCH_SERIALIZE calls __construct()). (Matteo)
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 14c5029ffffeb0bc91e1cd73352df557fa2e4ec5..24c51f39f6ccc031d41e4774d03ffb464a9ef1c9 100644 (file)
@@ -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));
                }
index 11bd18b9a5ecace9ad84d56d16d63e6687b1d0cc..fe902cb2445701c19fc3e0ea9c78fdbd96c7e6f6 100644 (file)
@@ -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));
                }