From ac3e75244c3fc216f6518e3c543dee1edc335e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Wed, 22 Jan 2025 09:39:57 +0100 Subject: [PATCH] Fix leak of SSL caches for auxiliary threads Whenever a thread creates MySQL connections using SSL params the thread-local caches are populated. These thread-local resources need to be free on thread exit via 'mysql_thread_end', otherwise these objects will be leak. This is not relevant for the fixed size thread-pools, but it's for workloads making use of temporary/auxiliary threads. --- lib/MySQL_Monitor.cpp | 5 ++++- lib/MySQL_Session.cpp | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/MySQL_Monitor.cpp b/lib/MySQL_Monitor.cpp index 0273ef8a1..b80752114 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -103,7 +103,7 @@ class ConsumerThread : public Thread { m_queue.add(item); } // this is intentional to EXIT immediately - return NULL; + goto cleanup; } @@ -123,6 +123,9 @@ class ConsumerThread : public Thread { delete item->data; delete item; } +cleanup: + // De-initializes per-thread structures. Required in all auxiliary threads using MySQL and SSL. + mysql_thread_end(); return NULL; } }; diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index c529cfbdd..ac23d0e87 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -329,6 +329,8 @@ __exit_kill_query_thread: delete ssl_params; ssl_params = NULL; } + // De-initializes per-thread structures. Required in all auxiliary threads using MySQL and SSL. + mysql_thread_end(); return NULL; }