diff options
author | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2010-02-01 23:04:09 +0000 |
---|---|---|
committer | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2010-02-01 23:04:09 +0000 |
commit | 76fd218ed7de691f674c73b690c50f64cb8e898d (patch) | |
tree | dbccff4002fcdfaa11dd24450e2db6f33a7928bd /Foundation | |
parent | 1cee4156f3d51c838988175f6a42b9eb3a42024e (diff) |
[Author: dmaclach]
Clean up leak in GTMAbstractDOListenerTest and add guard against similar
leaks to GTMAbstractDOListener.
R=thomasvl
DELTA=15 (6 added, 0 deleted, 9 changed)
Diffstat (limited to 'Foundation')
-rw-r--r-- | Foundation/GTMAbstractDOListener.m | 4 | ||||
-rw-r--r-- | Foundation/GTMAbstractDOListenerTest.m | 22 |
2 files changed, 16 insertions, 10 deletions
diff --git a/Foundation/GTMAbstractDOListener.m b/Foundation/GTMAbstractDOListener.m index c77d0a6..cf24c77 100644 --- a/Foundation/GTMAbstractDOListener.m +++ b/Foundation/GTMAbstractDOListener.m @@ -253,7 +253,9 @@ static NSMutableSet *gAllListeners = nil; BOOL result = NO; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - + + _GTMDevAssert(!connection_, @"Connection_ should not be set. Was this " + @"listener already started? %@"); connection_ = [[NSConnection alloc] initWithReceivePort:port_ sendPort:nil]; NSProtocolChecker *checker = diff --git a/Foundation/GTMAbstractDOListenerTest.m b/Foundation/GTMAbstractDOListenerTest.m index 56e5a31..895af4a 100644 --- a/Foundation/GTMAbstractDOListenerTest.m +++ b/Foundation/GTMAbstractDOListenerTest.m @@ -250,23 +250,27 @@ enum { - (void)testAbstractDOListenerMultipleRegistration { TestServer *listener = - [[TestServer alloc] initWithRegisteredName:@"MyUniqueName" - protocol:@protocol(TestServerDOProtocol) - port:[NSMachPort port]]; + [[[TestServer alloc] initWithRegisteredName:@"MyUniqueName" + protocol:@protocol(TestServerDOProtocol) + port:[NSMachPort port]] autorelease]; [GTMUnitTestDevLog expectPattern:@"listening on.*"]; [listener runInCurrentThread]; TestServer *copyCat = - [[TestServer alloc] initWithRegisteredName:@"copyCat" - protocol:@protocol(TestServerDOProtocol) - port:[NSMachPort port]]; + [[[TestServer alloc] initWithRegisteredName:@"copyCat" + protocol:@protocol(TestServerDOProtocol) + port:[NSMachPort port]] autorelease]; STAssertTrue(([[copyCat registeredName] isEqualToString:@"copyCat"]), @"The name we set to register with is not correct."); - [listener setRegisteredName:@"MyUniqueName"]; + TestServer *listener2 = + [[[TestServer alloc] initWithRegisteredName:@"MyUniqueName" + protocol:@protocol(TestServerDOProtocol) + port:[NSMachPort port]] autorelease]; + [GTMUnitTestDevLog expectPattern:@"failed to register.*"]; - [listener runInCurrentThread]; - STAssertNil([listener connection], @"We should not have been able to created " + [listener2 runInCurrentThread]; + STAssertNil([listener2 connection], @"We should not have been able to create " @"a server with a name that has already been taken."); } |