Skip to content

Commit b7c34b7

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix memory leak after GC inside a foreach loop (#12572)
2 parents 93c57af + 004d895 commit b7c34b7

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Zend/tests/gc_047.phpt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GC 047: Leak after GC inside a foreach loop
3+
--INI--
4+
zend.enable_gc=1
5+
--FILE--
6+
<?php
7+
$a = [0, 1];
8+
foreach($a as &$v) {
9+
$a[0] =& $a;
10+
$a[1] = array();
11+
$a[1][0] =& $a[1];
12+
$b = 1;
13+
$a =& $b;
14+
gc_collect_cycles();
15+
break;
16+
}
17+
var_dump(gc_collect_cycles());
18+
?>
19+
--EXPECT--
20+
int(2)

Zend/zend_gc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2052,7 +2052,7 @@ static void zend_gc_root_tmpvars(void) {
20522052
}
20532053

20542054
uint32_t kind = range->var & ZEND_LIVE_MASK;
2055-
if (kind == ZEND_LIVE_TMPVAR) {
2055+
if (kind == ZEND_LIVE_TMPVAR || kind == ZEND_LIVE_LOOP) {
20562056
uint32_t var_num = range->var & ~ZEND_LIVE_MASK;
20572057
zval *var = ZEND_CALL_VAR(ex, var_num);
20582058
if (Z_REFCOUNTED_P(var)) {

0 commit comments

Comments
 (0)