From d6fb65adb0c4467cf8795dcf08b7278b87332da3 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 6 Jun 2025 20:32:16 +0200 Subject: [PATCH] QSharedPointer: fix uninit'ed field 'destroyer' The getAndRef(const QObject*) function failed to initialize ExternalRefCountData's destroyer field: the Qt::Uninitialized ctor doesn't init anything and there are no following assignments to the field, either. This probably a) caused some Coverty complaint (but I didn't check, because the Coverity UI is so clumsy) and b) was harmless, seeing as the -1 in strongref indicated that the destroyer is never to be fired. Fix it nevertheless by initializing it to nullptr. Amends the start of the public history. Pick-to: 6.9 6.8 6.5 Change-Id: Ib76b4bc00b08289bb8d6d58096b43501b47814d1 Reviewed-by: Thiago Macieira (cherry picked from commit 184d0bf2ec03dd3707b4b6326f6ba7e657afadc8) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/tools/qsharedpointer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index 5899cd9a548..ad8a3789084 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -1541,6 +1541,7 @@ QtSharedPointer::ExternalRefCountData *QtSharedPointer::ExternalRefCountData::ge ExternalRefCountData *x = ::new ExternalRefCountData(Qt::Uninitialized); x->strongref.storeRelaxed(-1); x->weakref.storeRelaxed(2); // the QWeakPointer that called us plus the QObject itself + x->destroyer = nullptr; ExternalRefCountData *ret; if (d->sharedRefcount.testAndSetOrdered(nullptr, x, ret)) { // ought to be release+acquire; this is acq_rel+acquire