Skip to content

Commit

Permalink
The allocation for the shared client could occur twice resulting in a…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
Evan Long committed Sep 15, 2011
1 parent 8d9b7ac commit b681971
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Example/Classes/AFGowallaAPIClient.m
Expand Up @@ -32,11 +32,10 @@
@implementation AFGowallaAPIClient

+ (id)sharedClient {
if (_sharedClient == nil) {
@synchronized(self) {
_sharedClient = [[self alloc] init];
}
}
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
_sharedClient = [[self alloc] init];
});

return _sharedClient;
}
Expand Down

0 comments on commit b681971

Please sign in to comment.