From fe36d47b371b71ad5fec30d4b5d7bf0baa0205ea Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 1 Oct 2020 09:56:16 +0200 Subject: Fix race condition in QThreadPool::clear Since we drop the lock while deleting threads, we need to handle the queue possibly being accessed and changed by the pool threads while clear() is running. Pick-to: 5.15 Fixes: QTBUG-87092 Change-Id: I7611edab90520454278502a58621e299f9cd1f6e Reviewed-by: Sona Kurazyan --- src/corelib/thread/qthreadpool.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/corelib/thread') diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp index 1b417aa8be..5765bf6b09 100644 --- a/src/corelib/thread/qthreadpool.cpp +++ b/src/corelib/thread/qthreadpool.cpp @@ -325,7 +325,8 @@ bool QThreadPoolPrivate::waitForDone(int msecs) void QThreadPoolPrivate::clear() { QMutexLocker locker(&mutex); - for (QueuePage *page : qAsConst(queue)) { + while (!queue.isEmpty()) { + auto *page = queue.takeLast(); while (!page->isFinished()) { QRunnable *r = page->pop(); if (r && r->autoDelete()) { @@ -335,9 +336,8 @@ void QThreadPoolPrivate::clear() locker.relock(); } } + delete page; } - qDeleteAll(queue); - queue.clear(); } /*! -- cgit v1.2.3