Skip to content

Commit 32052b8

Browse files
committed
• Fixed bug which could cause crash in SSYLazyNotificationCenter by accessing -userInfo of invalidated timer.
1 parent 337912d commit 32052b8

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

SSYLazyNotificationCenter.m

+15-10
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,21 @@ - (void)enqueueNotification:(NSNotification*)note
109109

110110
- (void)fire:(NSTimer*)timer {
111111
@synchronized(self) {
112-
/* Note 20171227 1 of 2. The following line will sometime crash on launch of BookMacster. */
113-
NSNotification* note = [timer userInfo] ;
114-
NSString* noteName = [note name] ;
115-
[[self fireTimers] removeObjectForKey:noteName] ;
116-
NSArray* observations = [[self observations] objectForKey:noteName] ;
117-
for (NSDictionary* observation in observations) {
118-
id observer = [observation objectForKey:constSSYLazyNotificationCenterObserver] ;
119-
SEL selector = NSSelectorFromString([observation objectForKey:constSSYLazyNotificationSelectorName]) ;
120-
[observer performSelector:selector
121-
withObject:note] ;
112+
/* Documentation of -[NSTimer userInfo] states:
113+
Do not access this property after the timer is invalidated.
114+
Indeed, in macOS 10.13.3 Beta 2-3, it causes a crash. So, we check
115+
it before doing anything. */
116+
if (timer.isValid) {
117+
NSNotification* note = [timer userInfo] ;
118+
NSString* noteName = [note name] ;
119+
[[self fireTimers] removeObjectForKey:noteName] ;
120+
NSArray* observations = [[self observations] objectForKey:noteName] ;
121+
for (NSDictionary* observation in observations) {
122+
id observer = [observation objectForKey:constSSYLazyNotificationCenterObserver] ;
123+
SEL selector = NSSelectorFromString([observation objectForKey:constSSYLazyNotificationSelectorName]) ;
124+
[observer performSelector:selector
125+
withObject:note] ;
126+
}
122127
}
123128
}
124129
}

0 commit comments

Comments
 (0)