Skip to content

Commit b0c1e5e

Browse files
committed
Fix memory leaks in case of error
1 parent 76af2b6 commit b0c1e5e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/sqlitejs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ static void js_error_to_sqlite (sqlite3_context *context, JSContext *js_ctx, JSV
469469
JSValue exception = JS_NULL;
470470

471471
if (JS_IsException(value)) {
472-
JSValue exception = JS_GetException(js_ctx);
472+
exception = JS_GetException(js_ctx);
473473
if (JS_IsObject(exception)) {
474474
JSValue message = JS_GetPropertyStr(js_ctx, exception, "message");
475475
if (!JS_IsException(message) && JS_IsString(message)) {
@@ -878,6 +878,7 @@ bool js_create_common (sqlite3_context *context, const char *type, const char *n
878878
if (!JS_IsFunction(js->context, func)) {
879879
const char *err_msg = (is_scalar) ? "JavaScript code must evaluate to a function in the form (function(args){ your_code_here })" : "JavaScript code must evaluate to a function in the form (function(str1, str2){ your_code_here })";
880880
js_error_to_sqlite(context, js->context, func, err_msg);
881+
JS_FreeValue(js->context, func);
881882
functionjs_free(fctx);
882883
return false;
883884
}

0 commit comments

Comments
 (0)