From 1812830ac3d5b167ddbb998cef58096d47da9989 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Thu, 2 Apr 2020 10:33:49 +0200 Subject: Fix potential race condition in QtConcurrent blocking methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QtConcurrent::blocking*() methods are using the ExceptionStore directly, which is not thread safe. In case if there's an exception thrown from multiple threads there may be a race condition. Added a lock to avoid that. Change-Id: I5de9928f91f5f43951b9bf9c4594694dc0ca0328 Reviewed-by: Vitaly Fanaskov Reviewed-by: MÃ¥rten Nordheim --- src/concurrent/qtconcurrentthreadengine.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/concurrent/qtconcurrentthreadengine.cpp') diff --git a/src/concurrent/qtconcurrentthreadengine.cpp b/src/concurrent/qtconcurrentthreadengine.cpp index 3293c49507d..cf424912b37 100644 --- a/src/concurrent/qtconcurrentthreadengine.cpp +++ b/src/concurrent/qtconcurrentthreadengine.cpp @@ -322,10 +322,13 @@ void ThreadEngineBase::run() // implements QRunnable. void ThreadEngineBase::handleException(const QException &exception) { - if (futureInterface) + if (futureInterface) { futureInterface->reportException(exception); - else if (!exceptionStore.hasException()) - exceptionStore.setException(exception); + } else { + QMutexLocker lock(&mutex); + if (!exceptionStore.hasException()) + exceptionStore.setException(exception); + } } #endif -- cgit v1.2.3