From 1155963c6c654ec79379921955b8be167c35c97f Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 23 Mar 2020 12:23:21 +0100 Subject: [PATCH] db: guard against no DB Maybe if we only use `/connect` we dont have ProfAccount. In that case we won't log anything. Only if a account is used we log. If this is the case or the init of the db didn't work we still want profanity to run but wont log anything to the db. --- src/database.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/database.c b/src/database.c index 54005c2b..de1d36fb 100644 --- a/src/database.c +++ b/src/database.c @@ -123,12 +123,20 @@ log_database_init(ProfAccount *account) void log_database_close(void) { - sqlite3_close(g_chatlog_database); - sqlite3_shutdown(); + if (g_chatlog_database) { + sqlite3_close(g_chatlog_database); + sqlite3_shutdown(); + g_chatlog_database = NULL; + } } void log_database_add(ProfMessage *message, gboolean is_muc) { + if (!g_chatlog_database) { + log_debug("log_database_add() called but db is not initialized"); + return; + } + char *err_msg; char *query;