Skip to content

Commit

Permalink
Fix DUMP_LEAKS memory leak false positive (#655)
Browse files Browse the repository at this point in the history
Run DUMP_LEAKS after finalizers run; they call js_free_rt too.

Fixes: #654
  • Loading branch information
bnoordhuis authored Nov 6, 2024
1 parent 83fe8f1 commit aedd829
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,16 @@ void JS_FreeRuntime(JSRuntime *rt)
if (rt->rt_info)
printf("\n");
}
#endif

while (rt->finalizers) {
JSRuntimeFinalizerState *fs = rt->finalizers;
rt->finalizers = fs->next;
fs->finalizer(rt, fs->arg);
js_free_rt(rt, fs);
}

#ifdef DUMP_LEAKS
if (check_dump_flag(rt, DUMP_LEAKS)) {
JSMallocState *s = &rt->malloc_state;
if (s->malloc_count > 1) {
Expand All @@ -2229,13 +2239,6 @@ void JS_FreeRuntime(JSRuntime *rt)
}
#endif

while (rt->finalizers) {
JSRuntimeFinalizerState *fs = rt->finalizers;
rt->finalizers = fs->next;
fs->finalizer(rt, fs->arg);
js_free_rt(rt, fs);
}

// FinalizationRegistry finalizers have run, no objects should remain
assert(list_empty(&rt->gc_obj_list));

Expand Down

0 comments on commit aedd829

Please sign in to comment.