From c587b52857ac5f74fb32571ab81ebaabb29e8bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Wed, 28 Feb 2024 23:46:47 +0100 Subject: [PATCH] core: tweak runtime destruction sequence Object might need to be freed after the JS context is gone, so delay destroying the runtime until the very end. --- src/vm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/vm.c b/src/vm.c index 8d13c3c5..c54a89f5 100644 --- a/src/vm.c +++ b/src/vm.c @@ -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); @@ -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); }