diff options
author | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2010-04-05 17:33:46 +0000 |
---|---|---|
committer | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2010-04-05 17:33:46 +0000 |
commit | 8464e3cdaa1b9b656350df3dc5f4254cbdc2adbc (patch) | |
tree | fab7c2f46696be18bcf902439ca2b4ec6e3364e0 | |
parent | 749900bde6560d275418871bff922df9cf1e9643 (diff) |
[Author: dmaclach]
Subtle issue in GTMLightweightProxy where it would leak (and return nil) if
you initialized it using a standard alloc] init] pattern instead if
initWithRepresentedObject:]. The init call would go to the proxy which
being nil would return nil, and you'd end up with both a leak and a nil pointer
nasty.
R=thomasvl
DELTA=13 (13 added, 0 deleted, 0 changed)
-rw-r--r-- | Foundation/GTMLightweightProxy.m | 4 | ||||
-rw-r--r-- | Foundation/GTMLightweightProxyTest.m | 9 |
2 files changed, 13 insertions, 0 deletions
diff --git a/Foundation/GTMLightweightProxy.m b/Foundation/GTMLightweightProxy.m index c00e44b..643478a 100644 --- a/Foundation/GTMLightweightProxy.m +++ b/Foundation/GTMLightweightProxy.m @@ -27,6 +27,10 @@ return self; } +- (id)init { + return [self initWithRepresentedObject:nil]; +} + #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 #if GTM_SUPPORT_GC // -[NSProxy finalize] is only in 10.5 or later diff --git a/Foundation/GTMLightweightProxyTest.m b/Foundation/GTMLightweightProxyTest.m index e50a9dc..01a1bb2 100644 --- a/Foundation/GTMLightweightProxyTest.m +++ b/Foundation/GTMLightweightProxyTest.m @@ -30,6 +30,15 @@ @implementation GTMLightweightProxyTest +- (void)testInit { + id proxy = [[[GTMLightweightProxy alloc] + initWithRepresentedObject:self] autorelease]; + STAssertNotNil(proxy, nil); + + proxy = [[[GTMLightweightProxy alloc] init] autorelease]; + STAssertNotNil(proxy, nil); +} + - (void)testProxy { id proxy = [[[GTMLightweightProxy alloc] initWithRepresentedObject:self] autorelease]; |