Skip to content

Commit

Permalink
Fix GH-13569: GC buffer unnecessarily grows up to GC_MAX_BUF_SIZE whe…
Browse files Browse the repository at this point in the history
…n scanning WeakMaps
  • Loading branch information
arnaud-lb committed Mar 5, 2024
1 parent 6a3c083 commit 6b57e2d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Zend/tests/gh13569.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
GH-13569: GC buffer grows up to GC_MAX_BUF_SIZE when scanning WeakMaps
--FILE--
<?php

$wm = new WeakMap();
$objs = [];
for ($i = 0; $i < 30_000; $i++) {
$objs[] = $obj = new stdClass;
$wm[$obj] = $obj;
}

gc_collect_cycles();

$tmp = $wm;
$tmp = null;

gc_collect_cycles();
?>
==DONE==
--EXPECT--
==DONE==
2 changes: 1 addition & 1 deletion Zend/zend_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ static void ZEND_FASTCALL gc_extra_root(zend_refcounted *ref)

if (EXPECTED(GC_HAS_UNUSED())) {
idx = GC_FETCH_UNUSED();
} else if (EXPECTED(GC_HAS_NEXT_UNUSED_UNDER_THRESHOLD())) {
} else if (EXPECTED(GC_HAS_NEXT_UNUSED())) {
idx = GC_FETCH_NEXT_UNUSED();
} else {
gc_grow_root_buffer();
Expand Down

0 comments on commit 6b57e2d

Please sign in to comment.