com php-src: Remove properties HT from nested GC data: Zend/tests/gc_042.phpt Zend/zend_gc.c

From: Date: Mon, 26 Aug 2019 15:49:37 +0000
Subject: com php-src: Remove properties HT from nested GC data: Zend/tests/gc_042.phpt Zend/zend_gc.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-108071@lists.php.net to get a copy of this message
Commit: 589542f50cbaf2bfc88aea79092df9db54f75ac6 Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 26 Aug 2019 17:48:05 +0200 Parents: 1e82a2d659aac6ef95a6820d4f6ac3684e07bcad Branches: PHP-7.2 PHP-7.3 PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=589542f50cbaf2bfc88aea79092df9db54f75ac6 Log: Remove properties HT from nested GC data The properties HT may be a GC root itself, so we need to remove it. I'm not sure this issue actually applies to PHP 7.2, but committing it there to be safe. As seen from the test case, the handling here is rather buggy on 7.2. Changed paths: A Zend/tests/gc_042.phpt M Zend/zend_gc.c Diff: diff --git a/Zend/tests/gc_042.phpt b/Zend/tests/gc_042.phpt new file mode 100644 index 0000000..a7c40fe --- /dev/null +++ b/Zend/tests/gc_042.phpt @@ -0,0 +1,26 @@ +--TEST-- +Object properties HT may need to be removed from nested data +--FILE-- +<?php + +class Test { + public function __destruct() { + $GLOBALS['x'] = $this; + } +} + +$t = new Test; +$t->x = new stdClass; +$t->x->t = $t; +$a = (array) $t->x; +unset($t, $a); +gc_collect_cycles(); +var_dump($x); + +// TODO: The destructor *should* be running here, but doesn't. +// This works in PHP >= 7.3 though. + +?> +--EXPECTF-- +Notice: Undefined variable: x in %s on line %d +NULL diff --git a/Zend/zend_gc.c b/Zend/zend_gc.c index d98598c..1b6d53a 100644 --- a/Zend/zend_gc.c +++ b/Zend/zend_gc.c @@ -1007,6 +1007,10 @@ tail_call: ref = Z_COUNTED_P(zv); goto tail_call; } + if (GC_ADDRESS(GC_INFO(ht)) != 0 && GC_REF_GET_COLOR(ht) == GC_BLACK) { + GC_TRACE_REF(ht, "removing from buffer"); + GC_REMOVE_FROM_BUFFER(ht); + } } else { return; }

« previous php.cvs (#108071) next »