summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <adam@sigterm.info>2016-09-25 14:37:01 -0400
committerGitHub <noreply@github.com>2016-09-25 14:37:01 -0400
commit3a8ff5d45624bc4f3dcd11531a7c4727a249ce01 (patch)
treeb0f9ae16e353096f25da3f46a1f2ef9123081f5b
parent0b783b66a4200746fdefe6899a1cfbacc5ba2b5f (diff)
parentde174149f734b50cede6f04e45eb493aa121d0ad (diff)
Merge pull request #177 from attilamolnar/2.0+sqliteleak
m_sqlite: Fix possible memory leak when opening a database fails
-rw-r--r--modules/extra/m_sqlite.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/modules/extra/m_sqlite.cpp b/modules/extra/m_sqlite.cpp
index d8b76011a..0699ee3eb 100644
--- a/modules/extra/m_sqlite.cpp
+++ b/modules/extra/m_sqlite.cpp
@@ -138,7 +138,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()