]> granicus.if.org Git - pdns/commitdiff
auth: Fix a memory leak when sqlite3_exec() fails
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 28 Jun 2019 12:08:10 +0000 (14:08 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 28 Jun 2019 12:08:10 +0000 (14:08 +0200)
pdns/ssqlite3.cc

index 752c72950b18779e5bbfc5c6ab4e00e8fdc7097d..507f2cd2353973e40bbe7250bae9c12870570bc3 100644 (file)
@@ -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);
+      }
     }
   }
 }