[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-cvs
Subject:    [PHP-CVS] [php-src] master: Merge branch 'PHP-8.2' into PHP-8.3
From:       Dmitry Stogov <noreply () php ! net>
Date:       2023-10-30 20:50:59
Message-ID: L1zDkBeUNtVOp0M0pwQfpG1k7mbmolt9B4NspVLaDg () main ! php ! net
[Download RAW message or body]

Author: Dmitry Stogov (dstogov)
Date: 2023-10-30T23:36:50+03:00

Commit: https://github.com/php/php-src/commit/004d8951ce25a9a781d7fb575314757297dff120
Raw diff: https://github.com/php/php-src/commit/004d8951ce25a9a781d7fb575314757297dff120.diff

Merge branch 'PHP-8.2' into PHP-8.3

* PHP-8.2:
  Fix memory leak after GC inside a foreach loop (#12572)

Changed paths:
  A  Zend/tests/gc_047.phpt
  M  Zend/zend_gc.c


Diff:

diff --git a/Zend/tests/gc_047.phpt b/Zend/tests/gc_047.phpt
new file mode 100644
index 000000000000..08403d1e99bc
--- /dev/null
+++ b/Zend/tests/gc_047.phpt
@@ -0,0 +1,20 @@
+--TEST--
+GC 047: Leak after GC inside a foreach loop
+--INI--
+zend.enable_gc=1
+--FILE--
+<?php
+$a = [0, 1];
+foreach($a as &$v) {
+    $a[0] =& $a;
+    $a[1] = array();
+    $a[1][0] =& $a[1];
+    $b = 1;
+    $a =& $b;
+    gc_collect_cycles();
+    break;
+}
+var_dump(gc_collect_cycles());
+?>
+--EXPECT--
+int(2)
diff --git a/Zend/zend_gc.c b/Zend/zend_gc.c
index 6a9762eb5497..b92ead02eb4a 100644
--- a/Zend/zend_gc.c
+++ b/Zend/zend_gc.c
@@ -2052,7 +2052,7 @@ static void zend_gc_root_tmpvars(void) {
 			}
 
 			uint32_t kind = range->var & ZEND_LIVE_MASK;
-			if (kind == ZEND_LIVE_TMPVAR) {
+			if (kind == ZEND_LIVE_TMPVAR || kind == ZEND_LIVE_LOOP) {
 				uint32_t var_num = range->var & ~ZEND_LIVE_MASK;
 				zval *var = ZEND_CALL_VAR(ex, var_num);
 				if (Z_REFCOUNTED_P(var)) {

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic