mirror of
https://github.com/DoneJS-Runtime/quickjs-done-nextgen.git
synced 2025-01-09 17:43:15 +00:00
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:
parent
83fe8f1166
commit
aedd829e61
1 changed files with 10 additions and 7 deletions
17
quickjs.c
17
quickjs.c
|
@ -2217,6 +2217,16 @@ void JS_FreeRuntime(JSRuntime *rt)
|
||||||
if (rt->rt_info)
|
if (rt->rt_info)
|
||||||
printf("\n");
|
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)) {
|
if (check_dump_flag(rt, DUMP_LEAKS)) {
|
||||||
JSMallocState *s = &rt->malloc_state;
|
JSMallocState *s = &rt->malloc_state;
|
||||||
if (s->malloc_count > 1) {
|
if (s->malloc_count > 1) {
|
||||||
|
@ -2229,13 +2239,6 @@ void JS_FreeRuntime(JSRuntime *rt)
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
// FinalizationRegistry finalizers have run, no objects should remain
|
||||||
assert(list_empty(&rt->gc_obj_list));
|
assert(list_empty(&rt->gc_obj_list));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue