From 13db433219ff99bd5f2aa140f8147210a1a19d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 16 Dec 2024 16:05:20 +0100 Subject: [PATCH] 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 Change-Id: If2c08840d465ae6d190c87a4720a537fe9caa8dc Reviewed-by: Timur Pocheptsov (cherry picked from commit 92012333d112dbdf2926117ec3bb123bd30ed9fc) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit c8ae8244b431e20e63eb8c6934b5c814c1e33582) --- src/corelib/kernel/qcore_mac_p.h | 3 +++ 1 file changed, 3 insertions(+) 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();