]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4589] Unrelated: fix a crash in UT when database is not available
authorAndrei Pavel <andrei@isc.org>
Thu, 25 Jun 2026 12:52:47 +0000 (15:52 +0300)
committerAndrei Pavel <andrei@isc.org>
Tue, 21 Jul 2026 07:52:34 +0000 (10:52 +0300)
src/hooks/dhcp/mysql/tests/mysql_host_data_source_unittest.cc
src/hooks/dhcp/pgsql/tests/pgsql_host_data_source_unittest.cc

index 65e238fcc7c440ae5a38b12ec6742c129b1bf569..38bde7b56d39135205cc5f558bbae7826faf3443 100644 (file)
@@ -79,10 +79,12 @@ public:
 
     /// @brief Destroys the HDS and the schema.
     void destroyTest() {
-        try {
-            hdsptr_->rollback();
-        } catch (...) {
-            // Rollback may fail if backend is in read only mode. That's ok.
+        if (hdsptr_) {
+            try {
+                hdsptr_->rollback();
+            } catch (...) {
+                // Rollback may fail if backend is in read only mode. That's ok.
+            }
         }
         HostMgr::delAllBackends();
         hdsptr_.reset();
@@ -1587,10 +1589,12 @@ MySQLHostMgrTest::SetUp() {
 
 void
 MySQLHostMgrTest::TearDown() {
-    try {
-        HostMgr::instance().getHostDataSource()->rollback();
-    } catch(...) {
-        // we don't care if we aren't in a transaction.
+    if (HostMgr::instance().getHostDataSource()) {
+        try {
+            HostMgr::instance().getHostDataSource()->rollback();
+        } catch(...) {
+            // we don't care if we aren't in a transaction.
+        }
     }
 
     HostMgr::delBackend("mysql");
index 449bbc907907cb645633a6299ec4999e63359470..d0593473fa164d1f044cba3ad6e35ef8ca9f5470 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2016-2025 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2016-2026 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -79,10 +79,12 @@ public:
 
     /// @brief Destroys the HDS and the schema.
     void destroyTest() {
-        try {
-            hdsptr_->rollback();
-        } catch (...) {
-            // Rollback may fail if backend is in read only mode. That's ok.
+        if (hdsptr_) {
+            try {
+                hdsptr_->rollback();
+            } catch (...) {
+                // Rollback may fail if backend is in read only mode. That's ok.
+            }
         }
         HostMgr::delAllBackends();
         hdsptr_.reset();
@@ -1538,10 +1540,12 @@ PgSQLHostMgrTest::SetUp() {
 
 void
 PgSQLHostMgrTest::TearDown() {
-    try {
-        HostMgr::instance().getHostDataSource()->rollback();
-    } catch(...) {
-        // we don't care if we aren't in a transaction.
+    if (HostMgr::instance().getHostDataSource()) {
+        try {
+            HostMgr::instance().getHostDataSource()->rollback();
+        } catch(...) {
+            // we don't care if we aren't in a transaction.
+        }
     }
 
     HostMgr::delBackend("postgresql");