The allocation for the shared client could occur twice resulting in a leak. Two

threads could pass the nil check. One would acquire the lock and create the
sharedClient. The second thread would eventually get the lock and also acquire
a sharedClient.
This commit is contained in:
Evan Long 2011-09-15 00:58:41 -07:00
parent 8d9b7ace34
commit b681971116

View file

@ -32,11 +32,10 @@ NSString * const kAFGowallaBaseURLString = @"https://api.gowalla.com/";
@implementation AFGowallaAPIClient @implementation AFGowallaAPIClient
+ (id)sharedClient { + (id)sharedClient {
if (_sharedClient == nil) { static dispatch_once_t oncePredicate;
@synchronized(self) { dispatch_once(&oncePredicate, ^{
_sharedClient = [[self alloc] init]; _sharedClient = [[self alloc] init];
} });
}
return _sharedClient; return _sharedClient;
} }