diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-01 09:56:16 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-01 20:55:04 +0200 |
commit | a5e6c50ef45e9b75867e1730c510f5739b00f176 (patch) | |
tree | a4ae5121eebbffbe24c7be1316e90dc51aa3f31b /src/corelib/thread/qthreadpool.cpp | |
parent | c9d2d93d0f800e0097e6b35d32a3bb251cf9070d (diff) |
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.
Fixes: QTBUG-87092
Change-Id: I7611edab90520454278502a58621e299f9cd1f6e
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
(cherry picked from commit fe36d47b371b71ad5fec30d4b5d7bf0baa0205ea)
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/corelib/thread/qthreadpool.cpp')
-rw-r--r-- | src/corelib/thread/qthreadpool.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp index 950c08ff80..93d0ffe695 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(); } /*! |