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: auth-4.2.0-rc3~19^2~3^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c5a5ba39660e0730124389a6412dbf492463274c;p=pdns auth: Fix a memory leak when sqlite3_exec() fails (cherry picked from commit a955a0100b081d1c6c1f5a267c790bcd0edd2252) --- diff --git a/pdns/ssqlite3.cc b/pdns/ssqlite3.cc index 752c72950..507f2cd23 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); + } } } }