From 8af70190966e38dc3a697859f427276aecfe44d4 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 13 May 2022 14:33:13 +0200 Subject: [PATCH] QReadWriteLock: fix data race in dtor We need an acquire fence before we delete the d-pointer. Otherwise, the reads that the dtor performs (QReadWriteLockPrivate contains many non-trivial data types such as std::mutex and QVLA), race against writes performed in other threads. The qWarning() indicates that QReadWriteLock can not rely on external synchronization to ensure a happens-before relationship between reads in the dtor and said writes. While an explicit fence just before the delete would suffice, the guard return is an extremely unlikely error case, and if we ignore it, then loadAcquire() is correct, so use that. Pick-to: 6.3 6.2 5.15 Change-Id: I29773b665a7f864cd6b07a294da326e8b10399b5 Reviewed-by: Sona Kurazyan Reviewed-by: Thiago Macieira --- src/corelib/thread/qreadwritelock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp index 9efe04d987..d5602974a6 100644 --- a/src/corelib/thread/qreadwritelock.cpp +++ b/src/corelib/thread/qreadwritelock.cpp @@ -124,7 +124,7 @@ QReadWriteLock::QReadWriteLock(RecursionMode recursionMode) */ QReadWriteLock::~QReadWriteLock() { - auto d = d_ptr.loadRelaxed(); + auto d = d_ptr.loadAcquire(); if (isUncontendedLocked(d)) { qWarning("QReadWriteLock: destroying locked QReadWriteLock"); return;