Skip to content

Commit

Permalink
Fix notification removal bug from last update
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Nov 12, 2024
1 parent 28ba778 commit b2e198c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2024-11-12 Richard Frith-Macdonald <[email protected]>

* Source/NSNotificationCenter.m:
Fix last update for case where we have a non-block notification.

2024-11-12 Richard Frith-Macdonald <[email protected]>

* Headers/GNUstepBase/GSIMap.h:
Expand Down
14 changes: 9 additions & 5 deletions Source/NSNotificationCenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ - (NSDictionary*) userInfo
typedef struct Obs {
id observer; /* Object to receive message. */
SEL selector; /* Method selector. */
BOOL owner; /* If we own the observer. */
int32_t retained; /* Retain count for structure. */
struct Obs *next; /* Next item in linked list. */
int retained; /* Retain count for structure. */
struct NCTbl *link; /* Pointer back to chunk table */
} Observation;

Expand Down Expand Up @@ -296,6 +297,11 @@ static inline BOOL doEqual(BOOL shouldHash, NSString* key1, NSString* key2)
obs->selector = s;
obs->observer = o;

/* Instances of GSNotificationObserverClass are owned by the Observation
* and must be explicitly released when the observation is removed.
*/
obs->owner = (GSNotificationObserverClass == object_getClass(o)) ? YES : NO;

return obs;
}

Expand Down Expand Up @@ -432,12 +438,10 @@ static void obsFree(Observation *o)
{
NCTable *t = o->link;

/* Instances of GSNotificationObserverClass are owned by the Observation
* and must be explicitly released when the observation is removed.
*/
if (object_getClass(o->observer) == GSNotificationObserverClass)
if (o->owner)
{
DESTROY(o->observer);
o->owner = NO;
}
o->link = (NCTable*)t->freeList;
t->freeList = o;
Expand Down

0 comments on commit b2e198c

Please sign in to comment.