]> git.kaiwu.me - njs.git/commitdiff
QuickJS: fix rejection reason leak in qjs_promise_result()
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 17 Nov 2026 01:10:02 +0000 (17:10 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Tue, 17 Nov 2026 22:09:33 +0000 (14:09 -0800)
Previously, when JS_EnqueueJob() failed, the cleanup freed the
original result argument instead of the job arguments.  For a
rejected result, that argument is JS_EXCEPTION, while the reason
taken with JS_GetException() leaked.

Free the job arguments, which own the callback and the reason or
result value in both cases.

The issue was introduced in 87086636 (0.8.10).

src/qjs.c

index f2ac6dde1d2b6c83972238c8e0997c8b307d327c..99a732d111ad6ab851ea23db432a934bb368ee6a 100644 (file)
--- a/src/qjs.c
+++ b/src/qjs.c
@@ -1637,8 +1637,8 @@ qjs_promise_result(JSContext *cx, JSValue result)
 
     if (JS_EnqueueJob(cx, qjs_promise_fill_trampoline, 2, arguments) < 0) {
         JS_FreeValue(cx, promise);
-        JS_FreeValue(cx, callbacks[is_error]);
-        JS_FreeValue(cx, result);
+        JS_FreeValue(cx, arguments[0]);
+        JS_FreeValue(cx, arguments[1]);
         return JS_EXCEPTION;
     }