]> git.kaiwu.me - quickjs.git/commitdiff
fixed memory leak in String constructor
authorFabrice Bellard <fabrice@bellard.org>
Wed, 16 Apr 2025 15:16:10 +0000 (17:16 +0200)
committerFabrice Bellard <fabrice@bellard.org>
Wed, 16 Apr 2025 15:16:10 +0000 (17:16 +0200)
quickjs.c

index 01988b4ae7aa65f862026ac24d9a6a54ea09bfd5..8b0b04f447df7b834a4ce8290139836dd5740350 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -41422,7 +41422,9 @@ static JSValue js_string_constructor(JSContext *ctx, JSValueConst new_target,
         JSString *p1 = JS_VALUE_GET_STRING(val);
 
         obj = js_create_from_ctor(ctx, new_target, JS_CLASS_STRING);
-        if (!JS_IsException(obj)) {
+        if (JS_IsException(obj)) {
+            JS_FreeValue(ctx, val);
+        } else {
             JS_SetObjectData(ctx, obj, val);
             JS_DefinePropertyValue(ctx, obj, JS_ATOM_length, JS_NewInt32(ctx, p1->len), 0);
         }