summaryrefslogtreecommitdiff
path: root/modules/extra/sqlite.cpp
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2016-10-07 19:14:51 -0400
committerAdam <Adam@anope.org>2016-10-07 19:14:51 -0400
commit67c0dfbe7f7bbcaca497bdb29e45c8d45874a7b3 (patch)
treec0e37c24a8bf69543d552de211bc5a1fb3262f1c /modules/extra/sqlite.cpp
parentfd1ec06b2f3c74b64e9816718750222781dbccb4 (diff)
m_sqlite: Fix possible memory leak when opening a database fails
Diffstat (limited to 'modules/extra/sqlite.cpp')
-rw-r--r--modules/extra/sqlite.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/modules/extra/sqlite.cpp b/modules/extra/sqlite.cpp
index 59acbf43f..2cd93923b 100644
--- a/modules/extra/sqlite.cpp
+++ b/modules/extra/sqlite.cpp
@@ -176,7 +176,16 @@ SQLiteService::SQLiteService(Module *o, const Anope::string &n, const Anope::str
{
int db = sqlite3_open_v2(database.c_str(), &this->sql, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
if (db != SQLITE_OK)
- throw SQL::Exception("Unable to open SQLite database " + database + ": " + sqlite3_errmsg(this->sql));
+ {
+ Anope::string exstr = "Unable to open SQLite database " + database;
+ if (this->sql)
+ {
+ exstr += ": ";
+ exstr += sqlite3_errmsg(this->sql);
+ sqlite3_close(this->sql);
+ }
+ throw SQL::Exception(exstr);
+ }
}
SQLiteService::~SQLiteService()