From dc9a279991431fc991fd716897972f71d6574169 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sat, 7 Jun 2025 10:36:44 -0400 Subject: [PATCH] ssb: Free sqlite3_exec errors. --- src/ssb.db.c | 11 +++++++++++ src/ssb.js.c | 14 +++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/ssb.db.c b/src/ssb.db.c index ff7176eb..2626a601 100644 --- a/src/ssb.db.c +++ b/src/ssb.db.c @@ -31,6 +31,10 @@ static int _tf_ssb_db_try_exec(sqlite3* db, const char* statement) { tf_printf("Error running '%s': %s.\n", statement, error ? error : sqlite3_errmsg(db)); } + if (error) + { + sqlite3_free(error); + } return result; } @@ -41,6 +45,13 @@ static void _tf_ssb_db_exec(sqlite3* db, const char* statement) if (result != SQLITE_OK) { tf_printf("Error running '%s': %s.\n", statement, error ? error : sqlite3_errmsg(db)); + } + if (error) + { + sqlite3_free(error); + } + if (result != SQLITE_OK) + { abort(); } } diff --git a/src/ssb.js.c b/src/ssb.js.c index 17e267fc..ac711965 100644 --- a/src/ssb.js.c +++ b/src/ssb.js.c @@ -279,10 +279,14 @@ static void _tf_ssb_swap_with_server_identity_work(tf_ssb_t* ssb, void* user_dat sqlite3_bind_text(statement, 2, work->user, -1, NULL) == SQLITE_OK && sqlite3_bind_text(statement, 3, work->id, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_DONE && sqlite3_changes(db) == 1) { - error = NULL; - if (sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, &error) != SQLITE_OK) + char* commit_error = NULL; + if (sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, &commit_error) != SQLITE_OK) { - work->error = error ? tf_strdup(error) : tf_strdup(sqlite3_errmsg(db)); + work->error = commit_error ? tf_strdup(commit_error) : tf_strdup(sqlite3_errmsg(db)); + } + if (commit_error) + { + sqlite3_free(commit_error); } } else @@ -300,6 +304,10 @@ static void _tf_ssb_swap_with_server_identity_work(tf_ssb_t* ssb, void* user_dat { work->error = error ? tf_strdup(error) : tf_strdup(sqlite3_errmsg(db)); } + if (error) + { + sqlite3_free(error); + } } else {