From afc6e4af264e1e166c911803a15cbf15ba998e64 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ciar=C3=A1n=20Walsh?= Date: Wed, 25 Jun 2008 01:00:43 +0100 Subject: [PATCH] The -connect: method would leak memory when called more than once * Source/SocketWrapper.m: Add a private prop for the hostname (remoteHost): Removed through use of a prop (connect:): Change from alloc'ing an NSString to creating an autorelease'd one --- Source/SocketWrapper.m | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Source/SocketWrapper.m b/Source/SocketWrapper.m index e74235a..0dac9ba 100644 --- a/Source/SocketWrapper.m +++ b/Source/SocketWrapper.m @@ -25,6 +25,7 @@ - (void)error:(NSString *)msg; +@property (copy, readwrite, getter=remoteHost, setter=setHostname:) NSString *hostname; @end @implementation SocketWrapper @@ -76,13 +77,7 @@ delegate = aDelegate; } -/** - * Returns the name of the host to whom we are currently connected. - */ -- (NSString *)remoteHost -{ - return hostname; -} +@synthesize hostname; /** * Connects to a socket on the port specified during init. This will dispatch another thread to do the @@ -158,7 +153,7 @@ [self error:@"Could not get remote hostname."]; } char *name = inet_ntoa(addr.sin_addr); - hostname = [[NSString alloc] initWithUTF8String:name]; + [self setHostname:[NSString stringWithUTF8String:name]]; [connection performSelectorOnMainThread:@selector(socketDidAccept:) withObject:nil waitUntilDone:NO]; -- 2.22.5