From: Remi Gacogne Date: Fri, 28 Jun 2019 12:08:10 +0000 (+0200) Subject: auth: Fix a memory leak when sqlite3_exec() fails X-Git-Tag: dnsdist-1.4.0-rc1~62^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F7998%2Fhead;p=thirdparty%2Fpdns.git auth: Fix a memory leak when sqlite3_exec() fails --- diff --git a/pdns/ssqlite3.cc b/pdns/ssqlite3.cc index 752c72950b..507f2cd235 100644 --- a/pdns/ssqlite3.cc +++ b/pdns/ssqlite3.cc @@ -235,10 +235,15 @@ void SSQLite3::execute(const string& query) { int rc; if (sqlite3_exec(m_pDB, query.c_str(), NULL, NULL, &errmsg) == SQLITE_BUSY) { if (m_in_transaction) { - throw("Failed to execute query: " + string(errmsg)); + std::string errstr(errmsg); + sqlite3_free(errmsg); + throw("Failed to execute query: " + errstr); } else { - if ((rc = sqlite3_exec(m_pDB, query.c_str(), NULL, NULL, &errmsg) != SQLITE_OK) && rc != SQLITE_DONE && rc != SQLITE_ROW) - throw("Failed to execute query: " + string(errmsg)); + if ((rc = sqlite3_exec(m_pDB, query.c_str(), NULL, NULL, &errmsg) != SQLITE_OK) && rc != SQLITE_DONE && rc != SQLITE_ROW) { + std::string errstr(errmsg); + sqlite3_free(errmsg); + throw("Failed to execute query: " + errstr); + } } } }