From 2a62b8b0823435e14675ae9bbe281ddd37206fcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sat, 19 Aug 2017 13:00:56 +0200 Subject: [PATCH] Fix a sqlite3 leak when the database fails to open --- src/database/database.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/database/database.cpp b/src/database/database.cpp index 0068b24..266b17e 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -23,12 +23,13 @@ void Database::open(const std::string& filename) // not, just leave things untouched sqlite3* new_db; auto res = sqlite3_open_v2(filename.data(), &new_db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr); + Database::close(); if (res != SQLITE_OK) { log_error("Failed to open database file ", filename, ": ", sqlite3_errmsg(new_db)); + sqlite3_close_v2(new_db); throw std::runtime_error(""); } - Database::close(); Database::db = new_db; Database::muc_log_lines.create(Database::db); Database::muc_log_lines.upgrade(Database::db); -- 2.45.2