Skip to content

Commit 3feea52

Browse files
committed
Dispatch delegate messages in a safer manner
Should address issues like https://rink.hockeyapp.net/manage/apps/101581/app_versions/18/crash_reas ons/20702812?order=asc&sort_by=date&type=crashes#crash_data
1 parent ea70424 commit 3feea52

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

ConnectionKit/CK2FileOperation.m

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,18 @@ - (void)tryToMessageDelegateSelector:(SEL)selector usingBlock:(void (^)(id <CK2F
327327
{
328328
CK2FileManager *manager = self.fileManager;
329329
NSAssert(manager, @"%@ disconnected from its manager too early", self.class);
330-
id <CK2FileManagerDelegate> delegate = manager.delegate;
331330

332-
if (!selector || [delegate respondsToSelector:selector]) // will crash if delegate is a zombie, as in https://rink.hockeyapp.net/manage/apps/101581/crash_reasons/21102964/multiple
333-
{
334-
[manager.delegateQueue addOperationWithBlock:^{
335-
block(manager.delegate); // I have a suspicion delegate is occasionally a zombie otherwise https://karelia.fogbugz.com/f/cases/236528
336-
}];
337-
}
331+
// Clients could change the delegate at any time. If we trust them to do so in concert with the
332+
// delegate queue, then that can be made reasonably safe by only accessing the delegate from
333+
// within the queue.
334+
// It's still inherently a bit dangerous though, as the client could change it on a different
335+
// queue, or could have specified a non-serial delegate queue.
336+
[manager.delegateQueue addOperationWithBlock:^{
337+
id <CK2FileManagerDelegate> delegate = manager.delegate;
338+
if (!selector || [delegate respondsToSelector:selector]) {
339+
block(delegate);
340+
}
341+
}];
338342
}
339343

340344
#pragma mark URL & Requests

0 commit comments

Comments
 (0)