]> git.kaiwu.me - njs.git/commitdiff
WebCrypto: free QuickJS values on allocation failures
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 17 Nov 2026 01:12:26 +0000 (17:12 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Tue, 17 Nov 2026 22:09:33 +0000 (14:09 -0800)
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).

external/qjs_webcrypto_module.c

index eb707c59011369848111bcf5e8027d25270dca4d..81c3017090184842f9530e869ca3bacc88972987 100644 (file)
@@ -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);
     }