Fix potential bug with recursing too many times duing gc

This commit is contained in:
2025-09-09 04:06:59 -07:00
parent 9282e0bbc6
commit 77cc3c45de
2 changed files with 6 additions and 2 deletions

View File

@ -658,19 +658,20 @@ static ptrdiff_t check_gc_root(RefcountContext *ctx, RefcountList **root_ptr) {
continue;
}
uintptr_t count;
queue = refcount_list_pop_full(queue, NULL, &ctx->alloc);
if (ht_has(counts, obj)) {
count = HT_UUNSTUFF(ht_get(counts, obj));
} else {
count = REFCOUNT_OBJECT_ENTRY(ctx, obj)->impl.counted.ref_count;
++seen_objects;
// don't recuse into objects multiple times
obj_held_refs(ctx, obj, &queue);
}
queue = refcount_list_pop_full(queue, NULL, &ctx->alloc);
if (count > 0) {
ht_insert(counts, obj, HT_STUFF(--count));
if (count == 0) {
++clear_objects;
}
obj_held_refs(ctx, obj, &queue);
}
}
ptrdiff_t freed_count = 0;