From 8c31c6529935cd9ee6f99bc38cfd182d5b3182e2 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Thu, 18 Nov 2010 08:38:34 +0100 Subject: Don't destroy Qt's internal pthread_key_t if it was not initialized MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The destructor function destroy_current_thread_data_key() was always called on library unload, even if the pthread_key_t was not initialized. This can cause us to destroy a key that doesn't belong to us, as pointed out in the task below. Fix this by creating a function static instance of a class whose destructor will destroy the key. Task-number: QTBUG-10861 Reviewed-by: Morten Sørvig --- src/corelib/thread/qthread_unix.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index f508c0a..75bc78a 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -136,15 +136,17 @@ static void destroy_current_thread_data(void *p) static void create_current_thread_data_key() { pthread_key_create(¤t_thread_data_key, destroy_current_thread_data); + static class destroy_current_thread_data_key + { + public: + ~destroy_current_thread_data_key() + { + pthread_key_delete(current_thread_data_key); + } + } d; + Q_UNUSED(d); } -static void destroy_current_thread_data_key() -{ - pthread_key_delete(current_thread_data_key); -} -Q_DESTRUCTOR_FUNCTION(destroy_current_thread_data_key) - - // Utility functions for getting, setting and clearing thread specific data. // In Symbian, TLS access is significantly faster than pthread_getspecific. // However Symbian does not have the thread destruction cleanup functionality -- cgit v0.12