From c011898ea0160543dcd5485563bc6c486f495e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 12 Jul 2024 15:41:24 +0200 Subject: [PATCH] Fix memory leak in JS_WriteObject2 If a SAB was written sab_tab will have been allocated. Free it if the user didn't provide a way to retrieve it. --- quickjs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/quickjs.c b/quickjs.c index fe774fb..49d1e8b 100644 --- a/quickjs.c +++ b/quickjs.c @@ -33957,6 +33957,8 @@ uint8_t *JS_WriteObject2(JSContext *ctx, size_t *psize, JSValue obj, *psize = s->dbuf.size; if (psab_tab) *psab_tab = s->sab_tab; + else + js_free(ctx, s->sab_tab); if (psab_tab_len) *psab_tab_len = s->sab_tab_len; return s->dbuf.buf;