]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Better version that also plug the leaks for errors != the ones tested for.
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 1 May 2020 10:26:51 +0000 (12:26 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 1 May 2020 10:26:51 +0000 (12:26 +0200)
pdns/ssqlite3.cc

index bb91ba4f348b8e895e94e2cce34231f93f5d49b8..e35b7fb9d0316985ed97f50105bf402849c18ca1 100644 (file)
@@ -234,19 +234,28 @@ std::unique_ptr<SSqlStatement> SSQLite3::prepare(const string& query, int nparam
 
 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);
+  std::string errstr1;
+  int rc = sqlite3_exec(m_pDB, query.c_str(), NULL, NULL, &errmsg);
+  if (rc != 0) {
+    errstr1 = errmsg;
     sqlite3_free(errmsg);
+  }
+  if (rc == SQLITE_BUSY) {
     if (m_in_transaction) {
       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 errstr2(errmsg);
+      rc = sqlite3_exec(m_pDB, query.c_str(), NULL, NULL, &errmsg);
+      std::string errstr2;
+      if (rc != 0)  {
+        errstr2 = errmsg;
         sqlite3_free(errmsg);
+      }
+      if (rc != SQLITE_OK && rc != SQLITE_DONE && rc != SQLITE_ROW) {
         throw("Failed to execute query: " + errstr2);
       }
     }
+  } else if (rc != 0) {
+    throw("Failed to execute query: " + errstr1);
   }
 }