Author: geechorama
Date: Wed Feb 10 01:03:01 2010
New Revision: 908303
URL: http://svn.apache.org/viewvc?rev=908303&view=rev
Log:
THRIFT-687. Fix memory leak in TSocketServer.
Modified:
incubator/thrift/trunk/lib/cocoa/src/server/TSocketServer.m
Modified: incubator/thrift/trunk/lib/cocoa/src/server/TSocketServer.m
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cocoa/src/server/TSocketServer.m?rev=908303&r1=908302&r2=908303&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cocoa/src/server/TSocketServer.m (original)
+++ incubator/thrift/trunk/lib/cocoa/src/server/TSocketServer.m Wed Feb 10
01:03:01 2010
@@ -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:)