THRIFT-687.  Fix memory leak in TSocketServer.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@908303 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cocoa/src/server/TSocketServer.m b/lib/cocoa/src/server/TSocketServer.m
index 56a5bea..23b3d10 100644
--- a/lib/cocoa/src/server/TSocketServer.m
+++ b/lib/cocoa/src/server/TSocketServer.m
@@ -48,6 +48,7 @@
   int fd = -1;
   CFSocketRef socket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_STREAM, IPPROTO_TCP, 0, NULL, NULL);
   if (socket) {
+    CFSocketSetSocketFlags(socket, CFSocketGetSocketFlags(socket) & ~kCFSocketCloseOnInvalidate);
     fd = CFSocketGetNative(socket);
     int yes = 1;
     setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes));
@@ -60,6 +61,8 @@
     addr.sin_addr.s_addr = htonl(INADDR_ANY);
     NSData *address = [NSData dataWithBytes:&addr length:sizeof(addr)];
     if (CFSocketSetAddress(socket, (CFDataRef)address) != kCFSocketSuccess) {
+      CFSocketInvalidate(socket);
+      CFRelease(socket);
       NSLog(@"*** Could not bind to address");
       return nil;
     }
@@ -72,6 +75,10 @@
   mSocketFileHandle = [[NSFileHandle alloc] initWithFileDescriptor: fd
                                                     closeOnDealloc: YES];
   
+  // throw away our socket
+  CFSocketInvalidate(socket);
+  CFRelease(socket);
+  
     // register for notifications of accepted incoming connections
   [[NSNotificationCenter defaultCenter] addObserver: self
                                            selector: @selector(connectionAccepted:)