Skip to content

Commit aedd829

Browse files
authored
Fix DUMP_LEAKS memory leak false positive (#655)
Run DUMP_LEAKS after finalizers run; they call js_free_rt too. Fixes: #654
1 parent 83fe8f1 commit aedd829

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

quickjs.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,16 @@ void JS_FreeRuntime(JSRuntime *rt)
22172217
if (rt->rt_info)
22182218
printf("\n");
22192219
}
2220+
#endif
2221+
2222+
while (rt->finalizers) {
2223+
JSRuntimeFinalizerState *fs = rt->finalizers;
2224+
rt->finalizers = fs->next;
2225+
fs->finalizer(rt, fs->arg);
2226+
js_free_rt(rt, fs);
2227+
}
2228+
2229+
#ifdef DUMP_LEAKS
22202230
if (check_dump_flag(rt, DUMP_LEAKS)) {
22212231
JSMallocState *s = &rt->malloc_state;
22222232
if (s->malloc_count > 1) {
@@ -2229,13 +2239,6 @@ void JS_FreeRuntime(JSRuntime *rt)
22292239
}
22302240
#endif
22312241

2232-
while (rt->finalizers) {
2233-
JSRuntimeFinalizerState *fs = rt->finalizers;
2234-
rt->finalizers = fs->next;
2235-
fs->finalizer(rt, fs->arg);
2236-
js_free_rt(rt, fs);
2237-
}
2238-
22392242
// FinalizationRegistry finalizers have run, no objects should remain
22402243
assert(list_empty(&rt->gc_obj_list));
22412244

0 commit comments

Comments
 (0)