diff options
authorThiago Macieira <>2019-07-30 08:54:30 -0700
committerThiago Macieira <>2019-08-05 10:14:47 -0700
commit64d949207686a0225a78de572548a5361e340ae3 (patch)
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 <> Reviewed-by: Olivier Goffart (Woboq GmbH) <>
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()
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();