From a955a0100b081d1c6c1f5a267c790bcd0edd2252 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 28 Jun 2019 14:08:10 +0200 Subject: [PATCH] auth: Fix a memory leak when sqlite3_exec() fails --- pdns/ssqlite3.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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); + } } } } -- 2.40.0