Skip to content

Commit 7597fc7

Browse files
authored
Fix potential atom leak in JS_ReadFunctionTag (#380)
1 parent 8dcdb92 commit 7597fc7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

quickjs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33883,7 +33883,7 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s)
3388333883
if (bc_get_u8(s, &v8))
3388433884
goto fail;
3388533885
bc.js_mode = v8;
33886-
if (bc_get_atom(s, &bc.func_name)) //@ atom leak if failure
33886+
if (bc_get_atom(s, &bc.func_name))
3388733887
goto fail;
3388833888
if (bc_get_leb128_u16(s, &bc.arg_count))
3388933889
goto fail;
@@ -33914,9 +33914,10 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s)
3391433914

3391533915
b = js_mallocz(ctx, function_size);
3391633916
if (!b)
33917-
return JS_EXCEPTION;
33917+
goto fail;
3391833918

3391933919
memcpy(b, &bc, sizeof(*b));
33920+
bc.func_name = JS_ATOM_NULL;
3392033921
b->header.ref_count = 1;
3392133922
if (local_count != 0) {
3392233923
b->vardefs = (void *)((uint8_t*)b + vardefs_offset);
@@ -34059,6 +34060,7 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s)
3405934060
b->realm = JS_DupContext(ctx);
3406034061
return obj;
3406134062
fail:
34063+
JS_FreeAtom(ctx, bc.func_name);
3406234064
JS_FreeValue(ctx, obj);
3406334065
return JS_EXCEPTION;
3406434066
}

0 commit comments

Comments
 (0)