Fix DUMP_LEAKS memory leak false positive (#655)

Run DUMP_LEAKS after finalizers run; they call js_free_rt too.

Fixes: https://github.com/quickjs-ng/quickjs/issues/654
This commit is contained in:
Ben Noordhuis 2024-11-06 22:56:10 +01:00 committed by GitHub
parent 83fe8f1166
commit aedd829e61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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) {
@ -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));