summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-12-16 16:05:20 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-12-17 13:45:36 +0100
commit92012333d112dbdf2926117ec3bb123bd30ed9fc (patch)
tree75cc461714053ead7c16107c218b0f98d2e238b7 /src
parenta56a6ba22dbd633bfa2f2f591a0e26246c4729c1 (diff)
QObjCWeakPointer: Clear existing associated object on assignment
If the existing m_object is the same as the incoming object the call to objc_setAssociatedObject in trackObjectLifetime will release the existing WeakPointerLifetimeTracker after assigning a new one, which means we'd clear the QObjCWeakPointer's object. We now reset the state up front. Fixes: QTBUG-132256 Pick-to: 6.8 6.9 Change-Id: If2c08840d465ae6d190c87a4720a537fe9caa8dc Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qcore_mac_p.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h
index 30590ef2303..51efe0fe328 100644
--- a/src/corelib/kernel/qcore_mac_p.h
+++ b/src/corelib/kernel/qcore_mac_p.h
@@ -504,6 +504,9 @@ public:
QObjCWeakPointer &operator=(const QObjCWeakPointer &other)
{
QMacAutoReleasePool pool;
+#if !USE_OBJC_WEAK
+ objc_setAssociatedObject(m_object, this, nil, OBJC_ASSOCIATION_RETAIN);
+#endif
m_object = other.m_object;
#if !USE_OBJC_WEAK
trackObjectLifetime();