Skip to content

Commit

Permalink
Purge observations with dead weak references when trying to remove an…
Browse files Browse the repository at this point in the history
… observer
  • Loading branch information
rfm committed Jan 7, 2025
1 parent 4c9c691 commit dfd1526
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Source/NSNotificationCenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,10 @@ static void listFree(Observation *list)
static Observation *listPurge(Observation *list, id observer)
{
Observation *tmp;
id o;

while (list != ENDOBS && objc_loadWeak(&list->observer) == observer)
while (list != ENDOBS
&& ((o = objc_loadWeak(&list->observer)) == observer || nil == o))
{
tmp = list->next;
list->next = 0;
Expand All @@ -532,7 +534,7 @@ static void listFree(Observation *list)
tmp = list;
while (tmp->next != ENDOBS)
{
if (objc_loadWeak(&tmp->next->observer) == observer)
if ((o = objc_loadWeak(&tmp->next->observer)) == observer || nil == o)
{
Observation *next = tmp->next;

Expand Down Expand Up @@ -561,7 +563,7 @@ static void listFree(Observation *list)
{
Observation *list = node->value.ext;

if (observer == 0)
if (nil == observer)
{
listFree(list);
GSIMapRemoveKey(map, node->key);
Expand Down

0 comments on commit dfd1526

Please sign in to comment.