summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2019-07-30 08:54:30 -0700
committerThiago Macieira <thiago.macieira@intel.com>2019-08-05 10:14:47 -0700
commit64d949207686a0225a78de572548a5361e340ae3 (patch)
treebed366a853312316a0f12e06e66c27e65fdd4177 /src/corelib/thread
parent8c0787cfa1a906ebe25907515d86050303b127e7 (diff)
Fix race condition on qt_create_tls() on Windows
If this function is called by multiple threads, more than one could reach the mutex locking and call TlsAlloc(), but only the last one would save the data. The others would be leaked and, worse, be used by those other threads. [ChangeLog][QtCore][QObject] Fixed a resource leak caused by a race condition if multiple QObjects were created at the same time, for the first time in an application, from multiple threads (implies threads not started with QThread). Fixes: QTBUG-77238 Change-Id: Ife213d861bb14c1787e1fffd15b63a5818bcc807 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qthread_win.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp
index e56fe2c6ae..5c7642c26e 100644
--- a/src/corelib/thread/qthread_win.cpp
+++ b/src/corelib/thread/qthread_win.cpp
@@ -99,6 +99,8 @@ void qt_create_tls()
return;
static QBasicMutex mutex;
QMutexLocker locker(&mutex);
+ if (qt_current_thread_data_tls_index != TLS_OUT_OF_INDEXES)
+ return;
qt_current_thread_data_tls_index = TlsAlloc();
}