summaryrefslogtreecommitdiff
path: root/src/database
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2017-08-19 13:00:56 +0200
committerlouiz’ <louiz@louiz.org>2017-08-19 13:02:34 +0200
commit2a62b8b0823435e14675ae9bbe281ddd37206fcf (patch)
treea01b58c5c2ebc72bace665a2ec801d284cb86031 /src/database
parent9648fd286c16dc1b9154a7940820a5c7043b4836 (diff)
downloadbiboumi-2a62b8b0823435e14675ae9bbe281ddd37206fcf.tar.gz
biboumi-2a62b8b0823435e14675ae9bbe281ddd37206fcf.tar.bz2
biboumi-2a62b8b0823435e14675ae9bbe281ddd37206fcf.tar.xz
biboumi-2a62b8b0823435e14675ae9bbe281ddd37206fcf.zip
Fix a sqlite3 leak when the database fails to open
Diffstat (limited to 'src/database')
-rw-r--r--src/database/database.cpp3
1 files changed, 2 insertions, 1 deletions
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);