Permalink
Browse files

Fix a crash when TDSocketChangeTracker gets an error

During the -errorOccurred: method's call to [self stop], the delegate would end up releasing the tracker,
causing it to be dealloced prematurely. Moved the stop call to the end, and for safety's sake added a
temporary retain during the entire stream:handleEvent: call.
(Bug reported by Joerg Birkhold.)
  • Loading branch information...
1 parent a1328a5 commit 19b862dc4d3937b1c61c0a1311f9110bd1b73245 @snej snej committed Jan 4, 2013
Showing with 2 additions and 1 deletion.
  1. +2 −1 Source/ChangeTracker/TDSocketChangeTracker.m
@@ -392,7 +392,6 @@ - (void) errorOccurred: (NSError*)error {
[self performSelector: @selector(start) withObject: nil afterDelay: retryDelay];
} else {
Warn(@"%@: Can't connect, giving up: %@", self, error);
- [self stop];
// Map lower-level errors from CFStream to higher-level NSURLError ones:
if ($equal(error.domain, NSPOSIXErrorDomain)) {
@@ -403,11 +402,13 @@ - (void) errorOccurred: (NSError*)error {
}
self.error = error;
+ [self stop];
}
}
- (void) stream: (NSStream*)stream handleEvent: (NSStreamEvent)eventCode {
+ __unused id keepMeAround = self; // retain myself so I can't be dealloced during this method
switch (eventCode) {
case NSStreamEventHasBytesAvailable: {
LogTo(ChangeTracker, @"%@: HasBytesAvailable %@", self, stream);

0 comments on commit 19b862d

Please sign in to comment.