summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qsharedpointer.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-05-24 17:29:10 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2021-05-25 22:23:57 +0200
commit5e96c64afb274a3cc4364b1390ce0b776d637dd6 (patch)
tree83c53407283b943d9b6dd5de75e6c5cd317020f4 /src/corelib/tools/qsharedpointer.cpp
parentb45b9090c3b66d541f57f8d049c22247f8c115ca (diff)
QSharedPointer: Use matching new/delete
When a weak pointer calls getAndRef and there is no strong reference yet, getAndRef creates a new ExternalRefCountData. Normally, ExternalRefCountData is never constructed directly, only its subclasses are constructed via placement new into a memory buffer. To that end, ExternalRefCountData has a custom operator delete, which calls the global operator delete (do deallocate the memory buffer correctly). When using operator new directly in getAndRef, gcc notices a new/delete mismatch with the delete in the same function: global operator new matched with class operator delete. This isn't actually an issue in practice, as the class operator delete simply calls the global delete. But to avoid the warning, we can simply call the global operators explicitly. To make it clear that allocation of ExternalRefCountData requires some care, we additionally delete the class operator new, and only allow placement new (or usage of global operator new, as in getAndRef). Pick-to: 6.1 Task-number: QTBUG-93360 Change-Id: I132d1e4e07520eadc5b8f3f955c06aecec80c646 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qsharedpointer.cpp')
-rw-r--r--src/corelib/tools/qsharedpointer.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp
index 44cbad94f7..ef921a8284 100644
--- a/src/corelib/tools/qsharedpointer.cpp
+++ b/src/corelib/tools/qsharedpointer.cpp
@@ -1400,7 +1400,7 @@ QtSharedPointer::ExternalRefCountData *QtSharedPointer::ExternalRefCountData::ge
}
// we can create the refcount data because it doesn't exist
- ExternalRefCountData *x = new ExternalRefCountData(Qt::Uninitialized);
+ ExternalRefCountData *x = ::new ExternalRefCountData(Qt::Uninitialized);
x->strongref.storeRelaxed(-1);
x->weakref.storeRelaxed(2); // the QWeakPointer that called us plus the QObject itself
@@ -1411,7 +1411,7 @@ QtSharedPointer::ExternalRefCountData *QtSharedPointer::ExternalRefCountData::ge
// ~ExternalRefCountData has a Q_ASSERT, so we use this trick to
// only execute this if Q_ASSERTs are enabled
Q_ASSERT((x->weakref.storeRelaxed(0), true));
- delete x;
+ ::delete x;
ret->weakref.ref();
}
return ret;