Thrift-1264:TSocketClient is queried by run loop after deallocation in Cocoa
authorJake Farrell <jfarrell@apache.org>
Sun, 3 Mar 2013 03:51:55 +0000 (22:51 -0500)
committerJake Farrell <jfarrell@apache.org>
Sun, 3 Mar 2013 03:51:55 +0000 (22:51 -0500)
Client: cocoa
Patch: Jan Ruth

Fixes TSocketClient not deallocated correctly.

lib/cocoa/src/transport/TSocketClient.m

index 256ecf3..1a7eea8 100644 (file)
 #import <CFNetwork/CFNetwork.h>
 #endif
 
+@interface TSocketClient ()
+{
+    NSInputStream * inputStream;
+       NSOutputStream * outputStream;
+}
+@end
+
 @implementation TSocketClient
 
 - (id) initWithHostname: (NSString *) hostname
                    port: (int) port
 {
-       NSInputStream * inputStream = NULL;
-       NSOutputStream * outputStream = NULL;
+       inputStream = NULL;
+       outputStream = NULL;
        CFReadStreamRef readStream = NULL;
        CFWriteStreamRef writeStream = NULL;
        CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (bridge_stub CFStringRef)hostname, port, &readStream, &writeStream);
        return self;
 }
 
+-(void)dealloc
+{
+    [inputStream close];
+    [inputStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
+    [inputStream setDelegate:nil];
+    [inputStream release_stub];
+    
+    [outputStream close];
+    [outputStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
+    [outputStream setDelegate:nil];
+    [outputStream release_stub];
+    [super dealloc_stub];
+}
+
 
 @end