From: Dmitry Volyntsev Date: Tue, 17 Nov 2026 01:12:26 +0000 (-0800) Subject: WebCrypto: free QuickJS values on allocation failures X-Git-Url: https://git.kaiwu.me/%7Bsubstring-before(@doc,%20'.xml')%7D.html?a=commitdiff_plain;h=0db44776c85c3740e4ad03aafcf879a0f916b980;p=njs.git WebCrypto: free QuickJS values on allocation failures Previously, qjs_webcrypto_key_make() returned without freeing the new CryptoKey object when allocating its native data failed, deriveKey() did not free the derived CryptoKey when allocating the output failed, and the CryptoKey.algorithm getter did not free the hash name when allocating the hash object failed. The values leaked; with debug QuickJS the first two also triggered the gc_obj_list assertion in JS_FreeRuntime(). Free the values on these paths. The issue was introduced in 75ca26f8 (0.8.10). --- diff --git a/external/qjs_webcrypto_module.c b/external/qjs_webcrypto_module.c index eb707c59..81c30170 100644 --- a/external/qjs_webcrypto_module.c +++ b/external/qjs_webcrypto_module.c @@ -2296,6 +2296,7 @@ qjs_webcrypto_derive(JSContext *cx, JSValueConst this_val, int argc, k = js_malloc(cx, njs_max(length, 1)); if (k == NULL) { + JS_FreeValue(cx, dkey_value); JS_ThrowOutOfMemory(cx); return JS_EXCEPTION; } @@ -5292,6 +5293,7 @@ qjs_webcrypto_key_algorithm(JSContext *cx, JSValueConst this_val) ret = JS_NewObject(cx); if (JS_IsException(ret)) { + JS_FreeValue(cx, hash); JS_FreeValue(cx, obj); return JS_EXCEPTION; } @@ -5510,6 +5512,7 @@ qjs_webcrypto_key_make(JSContext *cx, qjs_webcrypto_algorithm_t *alg, k = js_mallocz(cx, sizeof(qjs_webcrypto_key_t)); if (k == NULL) { + JS_FreeValue(cx, key); return JS_ThrowOutOfMemory(cx); }