From 64d949207686a0225a78de572548a5361e340ae3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 30 Jul 2019 08:54:30 -0700 Subject: 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) --- src/corelib/thread/qthread_win.cpp | 2 ++ 1 file changed, 2 insertions(+) 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(); } -- cgit v1.2.3