]> granicus.if.org Git - php/commitdiff
Fixed bug #68652 (segmentation fault in destructor)
authorDmitry Stogov <dmitry@zend.com>
Mon, 6 Apr 2015 15:11:41 +0000 (18:11 +0300)
committerDmitry Stogov <dmitry@zend.com>
Mon, 6 Apr 2015 15:11:41 +0000 (18:11 +0300)
NEWS
Zend/tests/bug68652.phpt [new file with mode: 0644]
Zend/zend_opcode.c

diff --git a/NEWS b/NEWS
index 2bc4f7c9cdbbd0afbd4dbfeda4595abd4bdddc7a..3e5dcce12b7aeba0aab419cabf640aa954b8ae6f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2015, PHP 5.5.25
 
+- Core:
+  . Fixed bug #68652 (segmentation fault in destructor). (Dmitry)
+
 - cURL:
   . Fixed bug #68739 (Missing break / control flow). (Laruence)
 
diff --git a/Zend/tests/bug68652.phpt b/Zend/tests/bug68652.phpt
new file mode 100644 (file)
index 0000000..be65513
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+Bug #68652 (segmentation fault in destructor)
+--FILE--
+<?php
+class Foo {
+
+    private static $instance;
+    public static function getInstance() {
+        if (isset(self::$instance)) {
+            return self::$instance;
+        }
+        return self::$instance = new self();
+    }
+
+    public function __destruct() {
+        Bar::getInstance();
+    }
+}
+
+class Bar {
+
+    private static $instance;
+    public static function getInstance() {
+        if (isset(self::$instance)) {
+            return self::$instance;
+        }
+        return self::$instance = new self();
+    }
+
+    public function __destruct() {
+        Foo::getInstance();
+    }
+}
+
+
+$foo = new Foo();
+?>
+--EXPECTF--
+Fatal error: Access to undeclared static property: Bar::$instance in %sbug68652.php on line %d
+
index b8e850d629de7573b77fae6ffc2fd2533a1f4e58..6c61d1aafaa729dedda682c76bd01e8da2c77b47 100644 (file)
@@ -162,16 +162,16 @@ static inline void cleanup_user_class_data(zend_class_entry *ce TSRMLS_DC)
                zend_hash_apply(&ce->function_table, (apply_func_t) zend_cleanup_function_data_full TSRMLS_CC);
        }
        if (ce->static_members_table) {
+               zval *static_members = ce->static_members_table;
+               int count = ce->default_static_members_count;
                int i;
 
-               for (i = 0; i < ce->default_static_members_count; i++) {
-                       if (ce->static_members_table[i]) {
-                               zval *p = ce->static_members_table[i];
-                               ce->static_members_table[i] = NULL;
-                               zval_ptr_dtor(&p);
-                       }
+               ce->default_static_members_count = 0;
+               ce->default_static_members_table = ce->static_members_table = NULL;
+               for (i = 0; i < count; i++) {
+                       zval_ptr_dtor(&static_members[i]);
                }
-               ce->static_members_table = NULL;
+               efree(static_members);
        }
 }