Skip to content

Commit

Permalink
Fix leak of weak references (#323)
Browse files Browse the repository at this point in the history

In the case where an object has been deallocated, fetching the old value of a weak reference to it returns nil.  If we are assigning nil to the weak reference we can't abort processing early (when we check that old and new values are the same) as that will leave the weak reference in place when the calling code thinks it has destroyed it.
  • Loading branch information
rfm authored Dec 21, 2024
1 parent 38933c1 commit 0bef56a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions arc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,9 @@ static BOOL setObjectHasWeakRefs(id obj)
WeakRef *oldRef;
id old;
loadWeakPointer(addr, &old, &oldRef);
// If the old and new values are the same, then we don't need to do anything.
if (old == obj)
// If the old and new values are the same, then we don't need to do anything
// unless we are deleting the weak reference by storing NULL to it.
if ((old == obj) && ((obj != NULL) || (NULL == oldRef)))
{
return obj;
}
Expand Down

0 comments on commit 0bef56a

Please sign in to comment.