Skip to content

Commit

Permalink
make sure that we don't track anymore the task and the filehandle if …
Browse files Browse the repository at this point in the history
…we close the connection. The notification can happen after dealloc
  • Loading branch information
Jérôme Lebel committed Oct 19, 2012
1 parent 81cbaba commit c0299fc
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions Sources/Helpers/MHTunnel.m
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,24 @@ - (void)start
}
}

- (void)_releaseFileHandleAndTask
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSTaskDidTerminateNotification object:_task];
[_task release];
_task = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:_fileHandle];
[_fileHandle release];
_fileHandle = nil;
self.running = NO;
self.connected = NO;
_tunnelError = MHNoTunnelError;
if ([_delegate respondsToSelector:@selector(tunnelDidStop:)]) [_delegate tunnelDidStop:self];
}

- (void)stop
{
[_task terminate];
[self _releaseFileHandleAndTask];
}

- (void)fileHandleNotification:(NSNotification *)notification
Expand All @@ -325,16 +340,7 @@ - (void)fileHandleNotification:(NSNotification *)notification

- (void)taskNotification:(NSNotification *)notification
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSTaskDidTerminateNotification object:_task];
[_task release];
_task = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:_fileHandle];
[_fileHandle release];
_fileHandle = nil;
self.running = NO;
self.connected = NO;
_tunnelError = MHNoTunnelError;
if ([_delegate respondsToSelector:@selector(tunnelDidStop:)]) [_delegate tunnelDidStop:self];
[self _releaseFileHandleAndTask];
}

- (void)readStatus
Expand Down

0 comments on commit c0299fc

Please sign in to comment.