diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-11-18 07:38:34 (GMT) |
---|---|---|
committer | Qt Commercial Integration <QtCommercial@digia.com> | 2012-01-31 10:25:01 (GMT) |
commit | a1d03a293fd918af191ae94f0aea17ee8526db08 (patch) | |
tree | 3ff379cc44b68f307678138eac16bba9a50060ee /src/corelib/thread | |
parent | 8242b1447998f51639d1e21417c31fe0d428a539 (diff) | |
download | Qt-a1d03a293fd918af191ae94f0aea17ee8526db08.zip Qt-a1d03a293fd918af191ae94f0aea17ee8526db08.tar.gz Qt-a1d03a293fd918af191ae94f0aea17ee8526db08.tar.bz2 |
Don't destroy Qt's internal pthread_key_t if it was not initialized
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
Diffstat (limited to 'src/corelib/thread')
-rw-r--r-- | src/corelib/thread/qthread_unix.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index f7e80fd..87979c4 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -150,15 +150,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 |