Skip to content

Commit 114f3f2

Browse files
committed
fix: prevent memory leak in js_setup_aggregate on init_code failure
Ensure JS_FreeContext is called when init_code throws during aggregate setup. Previously, the context was not freed on exception, leading to a memory leak and a potential assertion failure in JS_FreeRuntime during shutdown.
1 parent db3c0c9 commit 114f3f2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/sqlitejs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,10 @@ static bool js_setup_aggregate (sqlite3_context *context, globaljs_context *js,
575575
bool is_error = JS_IsException(result);
576576
if (is_error) js_error_to_sqlite(context, ctx, result, NULL);
577577
JS_FreeValue(ctx, result);
578-
if (is_error) return false;
578+
if (is_error) {
579+
JS_FreeContext(ctx);
580+
return false;
581+
}
579582
}
580583

581584
JSValue step_func = JS_NULL;

0 commit comments

Comments
 (0)