]> granicus.if.org Git - php/commitdiff
Fixed bug #78589
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 23 Sep 2019 10:39:12 +0000 (12:39 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 24 Sep 2019 10:17:21 +0000 (12:17 +0200)
Don't protect GC while destroying zvals. We may need to add GC
roots during this phase.

Zend/tests/bug78589.phpt [new file with mode: 0644]
Zend/zend_gc.c

diff --git a/Zend/tests/bug78589.phpt b/Zend/tests/bug78589.phpt
new file mode 100644 (file)
index 0000000..ac4761f
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+Bug #78589: Memory leak with GC + __destruct()
+--FILE--
+<?php
+
+class Test {
+    public function __destruct() {}
+}
+
+$test = new Test;
+$test->foo = [&$test->foo];
+$ary = [&$ary, $test];
+unset($ary, $test);
+gc_collect_cycles();
+
+?>
+===DONE===
+--EXPECT--
+===DONE===
index b74a8e79b9298a4b03d190993818279589199da5..8b242c003ddc7638b992472e7776046e5d21d4bb 100644 (file)
@@ -1549,7 +1549,6 @@ ZEND_API int zend_gc_collect_cycles(void)
 
                /* Destroy zvals */
                GC_TRACE("Destroying zvals");
-               GC_G(gc_protected) = 1;
                current = GC_IDX2PTR(GC_FIRST_ROOT);
                last = GC_IDX2PTR(GC_G(first_unused));
                while (current != last) {
@@ -1600,7 +1599,6 @@ ZEND_API int zend_gc_collect_cycles(void)
 
                GC_TRACE("Collection finished");
                GC_G(collected) += count;
-               GC_G(gc_protected) = 0;
                GC_G(gc_active) = 0;
        }