Skip to content

Commit

Permalink
core: tweak runtime destruction sequence
Browse files Browse the repository at this point in the history
Object might need to be freed after the JS context is gone, so delay
destroying the runtime until the very end.
  • Loading branch information
saghul committed Feb 28, 2024
1 parent e7f42f9 commit c587b52
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,25 +228,20 @@ TJSRuntime *TJS_NewRuntimeInternal(bool is_worker, TJSRunOptions *options) {
}

void TJS_FreeRuntime(TJSRuntime *qrt) {
JS_RunGC(qrt->rt);

/* Close all loop handles. */
uv_close((uv_handle_t *) &qrt->jobs.prepare, NULL);
uv_close((uv_handle_t *) &qrt->jobs.idle, NULL);
uv_close((uv_handle_t *) &qrt->jobs.check, NULL);
uv_close((uv_handle_t *) &qrt->stop, NULL);

JS_FreeContext(qrt->ctx);
JS_FreeRuntime(qrt->rt);

/* Destroy CURLM handle. */
if (qrt->curl_ctx.curlm_h) {
curl_multi_cleanup(qrt->curl_ctx.curlm_h);
uv_close((uv_handle_t *) &qrt->curl_ctx.timer, NULL);
}

/* Destroy WASM runtime. */
m3_FreeEnvironment(qrt->wasm_ctx.env);
JS_FreeContext(qrt->ctx);
JS_RunGC(qrt->rt);

uv_walk(&qrt->loop, uv__walk, NULL);

Expand All @@ -267,6 +262,11 @@ void TJS_FreeRuntime(TJSRuntime *qrt) {
(void)closed;
#endif

/* Destroy WASM runtime. */
m3_FreeEnvironment(qrt->wasm_ctx.env);

JS_FreeRuntime(qrt->rt);

free(qrt);
}

Expand Down

0 comments on commit c587b52

Please sign in to comment.