Skip to content

Commit 6b57e2d

Browse files
committed
Fix GH-13569: GC buffer unnecessarily grows up to GC_MAX_BUF_SIZE when scanning WeakMaps
1 parent 6a3c083 commit 6b57e2d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Zend/tests/gh13569.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-13569: GC buffer grows up to GC_MAX_BUF_SIZE when scanning WeakMaps
3+
--FILE--
4+
<?php
5+
6+
$wm = new WeakMap();
7+
$objs = [];
8+
for ($i = 0; $i < 30_000; $i++) {
9+
$objs[] = $obj = new stdClass;
10+
$wm[$obj] = $obj;
11+
}
12+
13+
gc_collect_cycles();
14+
15+
$tmp = $wm;
16+
$tmp = null;
17+
18+
gc_collect_cycles();
19+
?>
20+
==DONE==
21+
--EXPECT--
22+
==DONE==

Zend/zend_gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ static void ZEND_FASTCALL gc_extra_root(zend_refcounted *ref)
718718

719719
if (EXPECTED(GC_HAS_UNUSED())) {
720720
idx = GC_FETCH_UNUSED();
721-
} else if (EXPECTED(GC_HAS_NEXT_UNUSED_UNDER_THRESHOLD())) {
721+
} else if (EXPECTED(GC_HAS_NEXT_UNUSED())) {
722722
idx = GC_FETCH_NEXT_UNUSED();
723723
} else {
724724
gc_grow_root_buffer();

0 commit comments

Comments
 (0)