]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4207] fixed mysql lib unload
authorRazvan Becheriu <razvan@isc.org>
Mon, 3 Nov 2025 12:26:31 +0000 (14:26 +0200)
committerRazvan Becheriu <razvan@isc.org>
Fri, 21 Nov 2025 13:41:29 +0000 (13:41 +0000)
src/lib/mysql/mysql_connection.cc
src/lib/mysql/mysql_connection.h

index 8874f9503c8e8baf31cc52503dbbab0bab92eee7..7c63257d8d6bc6e87a0efbbf53fcf389c4c37781 100644 (file)
@@ -31,11 +31,9 @@ using namespace std;
 namespace isc {
 namespace db {
 
-std::string MySqlConnection::KEA_ADMIN_ = KEA_ADMIN;
+static MySqlLibraryInit init;
 
-int MySqlHolder::atexit_ = [] {
-    return atexit([] { mysql_library_end(); });
-}();
+std::string MySqlConnection::KEA_ADMIN_ = KEA_ADMIN;
 
 /// @todo: Migrate this default value to src/bin/dhcpX/simple_parserX.cc
 const int MYSQL_DEFAULT_CONNECTION_TIMEOUT = 5; // seconds
index c7b352a9c098286f29ae9911e4bd880447ceda73..ea040867de0f1c380b365bc599b8e2e7bb71fa92 100644 (file)
@@ -161,8 +161,6 @@ public:
     }
 
 private:
-    /// @brief Variable used for its static property to call atexit() once.
-    static int atexit_;
 
     /// @brief Initialization context
     MYSQL* mysql_;
@@ -836,6 +834,19 @@ public:
     static std::string KEA_ADMIN_;
 };
 
+/// @brief Structure used to initialize and clean up after MySQL library.
+struct MySqlLibraryInit {
+    /// @brief Constructor.
+    MySqlLibraryInit() {
+        mysql_library_init(0, 0, 0);
+    }
+
+    /// @brief Destructor.
+    ~MySqlLibraryInit() {
+        mysql_library_end();
+    }
+};
+
 } // end of isc::db namespace
 } // end of isc namespace