From c367f7e2fd2bf0147e950131f4b7887d178110f6 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Tue, 1 Jul 2025 23:01:57 -0700 Subject: [PATCH] Modules: fixed qjs engine after bellard/quickjs@458c34d2. Object leaks: ADDRESS REFS SHRF PROTO CONTENT 0x512000007fc0 1 [module] nginx: quickjs.c:1967: JS_FreeRuntime: Assertion `list_empty(&rt->gc_obj_list)' failed. After bellard/quickjs@458c34d2 modules are treated as GC objects and tracked in rt->gc_obj_list. Intermediary module object loaded in ngx_qjs_clone() using JS_ReadObject() needed to be freed for proper ref_count accounting. --- nginx/ngx_js.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nginx/ngx_js.c b/nginx/ngx_js.c index 448073b9..01d4bb2a 100644 --- a/nginx/ngx_js.c +++ b/nginx/ngx_js.c @@ -978,6 +978,11 @@ ngx_qjs_clone(ngx_js_ctx_t *ctx, ngx_js_loc_conf_t *cf, void *external) "js load module exception: %V", &exception); goto destroy; } + + if (i != length - 1) { + /* JS_EvalFunction() does JS_FreeValue(cx, rv) for the last rv. */ + JS_FreeValue(cx, rv); + } } if (JS_ResolveModule(cx, rv) < 0) { -- 2.47.3