From: Otto Moerbeek Date: Fri, 1 May 2020 09:55:51 +0000 (+0200) Subject: Better (actual) fix for leak reported by Coverity. X-Git-Tag: dnsdist-1.5.0-rc2~2^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e54d78b9fcf68499436ed4b320a45a40de9270a5;p=thirdparty%2Fpdns.git Better (actual) fix for leak reported by Coverity. Always free errmsg; use two diffferent string vars to avoid shadowing. Coverity 1401969. --- diff --git a/pdns/ssqlite3.cc b/pdns/ssqlite3.cc index 34fc86da48..bb91ba4f34 100644 --- a/pdns/ssqlite3.cc +++ b/pdns/ssqlite3.cc @@ -236,15 +236,15 @@ void SSQLite3::execute(const string& query) { char *errmsg; int rc; if (sqlite3_exec(m_pDB, query.c_str(), NULL, NULL, &errmsg) == SQLITE_BUSY) { + std::string errstr1(errmsg); + sqlite3_free(errmsg); if (m_in_transaction) { - std::string errstr(errmsg); - sqlite3_free(errmsg); - throw("Failed to execute query: " + errstr); + throw("Failed to execute query: " + errstr1); } else { if ((rc = sqlite3_exec(m_pDB, query.c_str(), NULL, NULL, &errmsg) != SQLITE_OK) && rc != SQLITE_DONE && rc != SQLITE_ROW) { - std::string errstr(errmsg); + std::string errstr2(errmsg); sqlite3_free(errmsg); - throw("Failed to execute query: " + errstr); + throw("Failed to execute query: " + errstr2); } } }