Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix crash in FinalizationRegistry when the observed object is GC'd #371

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -52141,11 +52141,16 @@ static void reset_weak_ref(JSRuntime *rt, JSWeakRefRecord **first_weak_ref)
fre = wr->u.fin_rec_entry;
JSFinalizationRegistryData *frd = JS_GetOpaque(fre->obj, JS_CLASS_FINALIZATION_REGISTRY);
assert(frd != NULL);
JSValue func = js_dup(frd->cb);
JSValue ret = JS_Call(frd->ctx, func, JS_UNDEFINED, 1, &fre->held_val);
JS_FreeValueRT(rt, func);
JS_FreeValueRT(rt, ret);
JS_FreeValueRT(rt, fre->held_val);
/**
* During the GC sweep phase the held object might be collected first.
*/
if (JS_IsLiveObject(frd->ctx->rt, fre->held_val)) {
JSValue func = js_dup(frd->cb);
JSValue ret = JS_Call(frd->ctx, func, JS_UNDEFINED, 1, &fre->held_val);
JS_FreeValueRT(rt, func);
JS_FreeValueRT(rt, ret);
JS_FreeValueRT(rt, fre->held_val);
}
JS_FreeValueRT(rt, fre->token);
js_free_rt(rt, fre);
break;
Expand Down
Loading