From: Andrei Pavel Date: Thu, 25 Jun 2026 12:52:47 +0000 (+0300) Subject: [#4589] Unrelated: fix a crash in UT when database is not available X-Git-Tag: Kea-3.3.0~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=078abc11d0834f88ced01b9cd4c421b7f5d9235e;p=thirdparty%2Fkea.git [#4589] Unrelated: fix a crash in UT when database is not available --- diff --git a/src/hooks/dhcp/mysql/tests/mysql_host_data_source_unittest.cc b/src/hooks/dhcp/mysql/tests/mysql_host_data_source_unittest.cc index 65e238fcc7..38bde7b56d 100644 --- a/src/hooks/dhcp/mysql/tests/mysql_host_data_source_unittest.cc +++ b/src/hooks/dhcp/mysql/tests/mysql_host_data_source_unittest.cc @@ -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"); diff --git a/src/hooks/dhcp/pgsql/tests/pgsql_host_data_source_unittest.cc b/src/hooks/dhcp/pgsql/tests/pgsql_host_data_source_unittest.cc index 449bbc9079..d0593473fa 100644 --- a/src/hooks/dhcp/pgsql/tests/pgsql_host_data_source_unittest.cc +++ b/src/hooks/dhcp/pgsql/tests/pgsql_host_data_source_unittest.cc @@ -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");