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:
parent
8d9b7ace34
commit
b681971116
1 changed files with 4 additions and 5 deletions
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue