From 7b362be91a91ef85bb292ebee8993272046657a4 Mon Sep 17 00:00:00 2001 From: Milivoje Legenovic Date: Feb 14 2021 15:16:58 +0000 Subject: Thread handle leak fix Signed-off-by: Milivoje Legenovic --- diff --git a/activemq-cpp.spec b/activemq-cpp.spec index 187a562..957985c 100644 --- a/activemq-cpp.spec +++ b/activemq-cpp.spec @@ -1,12 +1,13 @@ Name: activemq-cpp Version: 3.9.5 -Release: 1%{?dist} +Release: 2%{?dist} Summary: C++ implementation of JMS-like messaging client License: ASL 2.0 URL: http://activemq.apache.org/cms/ Source0: http://www.apache.org/dist/activemq/activemq-cpp/%{version}/activemq-cpp-library-%{version}-src.tar.gz Patch0: activemq-cpp-3.8.2-system-zlib.patch +Patch1: thread-handle-leak.patch BuildRequires: gcc BuildRequires: openssl-devel @@ -16,12 +17,12 @@ BuildRequires: cppunit-devel >= 1.10.2 BuildRequires: libuuid-devel %description -activemq-cpp is a JMS-like API for C++ for interfacing with Message -Brokers such as Apache ActiveMQ. C++ messaging service helps to make your -C++ client code much neater and easier to follow. To get a better feel for -CMS try the API Reference. -ActiveMQ-CPP is a client only library, a message broker such as Apache -ActiveMQ is still needed for your clients to communicate. +activemq-cpp is a JMS-like API for C++ for interfacing with Message +Brokers such as Apache ActiveMQ. C++ messaging service helps to make your +C++ client code much neater and easier to follow. To get a better feel for +CMS try the API Reference. +ActiveMQ-CPP is a client only library, a message broker such as Apache +ActiveMQ is still needed for your clients to communicate. %package devel Summary: C++ implementation header files for JMS-like messaging @@ -30,12 +31,12 @@ Requires: pkgconfig Requires: libuuid-devel %description devel -activemq-cpp is a JMS-like API for C++ for interfacing with Message -Brokers such as Apache ActiveMQ. C++ messaging service helps to make +activemq-cpp is a JMS-like API for C++ for interfacing with Message +Brokers such as Apache ActiveMQ. C++ messaging service helps to make your C++ client code much neater and easier to follow. To get a better -feel for CMS try the API Reference. ActiveMQ-CPP is a client only -library, a message broker such as Apache ActiveMQ is still needed -for your clients to communicate. +feel for CMS try the API Reference. ActiveMQ-CPP is a client only +library, a message broker such as Apache ActiveMQ is still needed +for your clients to communicate. %{name}-devel contains development header files. @@ -70,4 +71,3 @@ rm $RPM_BUILD_ROOT/%{_bindir}/example %{_includedir}/%{name}-%{version} %{_libdir}/pkgconfig/%{name}.pc %{_bindir}/activemqcpp-config - diff --git a/thread-handle-leak.patch b/thread-handle-leak.patch new file mode 100644 index 0000000..7a93883 --- /dev/null +++ b/thread-handle-leak.patch @@ -0,0 +1,81 @@ +diff --git a/src/main/decaf/internal/util/concurrent/PlatformThread.h b/src/main/decaf/internal/util/concurrent/PlatformThread.h +index 2446b942..3d10caa7 100644 +--- a/src/main/decaf/internal/util/concurrent/PlatformThread.h ++++ b/src/main/decaf/internal/util/concurrent/PlatformThread.h +@@ -149,7 +149,7 @@ namespace concurrent { + + public: // Thread Local Methods + +- static void createTlsKey(decaf_tls_key* key); ++ static void createTlsKey(decaf_tls_key* key, void (*destructor)(void*) = NULL); + + static void destroyTlsKey(decaf_tls_key key); + +diff --git a/src/main/decaf/internal/util/concurrent/Threading.cpp b/src/main/decaf/internal/util/concurrent/Threading.cpp +index ab48db29..29eb1526 100644 +--- a/src/main/decaf/internal/util/concurrent/Threading.cpp ++++ b/src/main/decaf/internal/util/concurrent/Threading.cpp +@@ -815,7 +815,7 @@ void Threading::initialize() { + PlatformThread::initPriorityMapping(Thread::MAX_PRIORITY + 1, library->priorityMapping); + + PlatformThread::createTlsKey(&(library->threadKey)); +- PlatformThread::createTlsKey(&(library->selfKey)); ++ PlatformThread::createTlsKey(&(library->selfKey), Threading::releaseThreadHandle); + PlatformThread::createMutex(&(library->globalLock)); + PlatformThread::createMutex(&(library->tlsLock)); + +@@ -1686,6 +1686,14 @@ void Threading::destoryThreadLocalSlot(int slot) { + PlatformThread::unlockMutex(library->tlsLock); + } + ++//////////////////////////////////////////////////////////////////////////////// ++void Threading::releaseThreadHandle(void* thread) { ++ ++ if (thread != NULL) { ++ detachFromCurrentThread((ThreadHandle*)thread); ++ } ++} ++ + //////////////////////////////////////////////////////////////////////////////// + void Threading::releaseCurrentThreadHandle() { + ThreadHandle* self = (ThreadHandle*)PlatformThread::getTlsValue(library->selfKey); +diff --git a/src/main/decaf/internal/util/concurrent/Threading.h b/src/main/decaf/internal/util/concurrent/Threading.h +index 2cb6e501..99527faf 100644 +--- a/src/main/decaf/internal/util/concurrent/Threading.h ++++ b/src/main/decaf/internal/util/concurrent/Threading.h +@@ -340,6 +340,7 @@ namespace concurrent { + + static ThreadHandle* attachToCurrentThread(); + static void detachFromCurrentThread(ThreadHandle* thread); ++ static void releaseThreadHandle(void*); + static void monitorEnterUsingThreadId(MonitorHandle* monitor, ThreadHandle* thread); + static bool monitorTryEnterUsingThreadId(MonitorHandle* monitor, ThreadHandle* thread); + static void monitorExitUsingThreadId(MonitorHandle* monitor, ThreadHandle* thread); +diff --git a/src/main/decaf/internal/util/concurrent/unix/PlatformThread.cpp b/src/main/decaf/internal/util/concurrent/unix/PlatformThread.cpp +index 64b14877..5c88d30d 100644 +--- a/src/main/decaf/internal/util/concurrent/unix/PlatformThread.cpp ++++ b/src/main/decaf/internal/util/concurrent/unix/PlatformThread.cpp +@@ -475,8 +475,8 @@ void PlatformThread::yeild() { + } + + //////////////////////////////////////////////////////////////////////////////// +-void PlatformThread::createTlsKey(decaf_tls_key* tlsKey) { +- pthread_key_create(tlsKey, NULL); ++void PlatformThread::createTlsKey(decaf_tls_key* tlsKey, void (*destructor)(void*)) { ++ pthread_key_create(tlsKey, destructor); + } + + //////////////////////////////////////////////////////////////////////////////// +diff --git a/src/main/decaf/internal/util/concurrent/windows/PlatformThread.cpp b/src/main/decaf/internal/util/concurrent/windows/PlatformThread.cpp +index 9b707734..53f5a7d1 100644 +--- a/src/main/decaf/internal/util/concurrent/windows/PlatformThread.cpp ++++ b/src/main/decaf/internal/util/concurrent/windows/PlatformThread.cpp +@@ -428,7 +428,7 @@ void PlatformThread::yeild() { + } + + //////////////////////////////////////////////////////////////////////////////// +-void PlatformThread::createTlsKey(decaf_tls_key* tlsKey) { ++void PlatformThread::createTlsKey(decaf_tls_key* tlsKey, void (*destructor)(void*)) { + if (tlsKey == NULL) { + throw NullPointerException(__FILE__, __LINE__, "TLS Key pointer must not be NULL."); + }