From c0299fcc8b1e9235b72c9a44d6d59fcfbf75ba2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebel?= Date: Fri, 19 Oct 2012 09:42:45 +0200 Subject: [PATCH] make sure that we don't track anymore the task and the filehandle if we close the connection. The notification can happen after dealloc --- Sources/Helpers/MHTunnel.m | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Sources/Helpers/MHTunnel.m b/Sources/Helpers/MHTunnel.m index 8a3a4796..eb96396e 100644 --- a/Sources/Helpers/MHTunnel.m +++ b/Sources/Helpers/MHTunnel.m @@ -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 @@ -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