Permalink
Browse files

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.
  • Loading branch information...
Evan Long
Evan Long committed Sep 15, 2011
1 parent 8d9b7ac commit b6819711167889944497f3144e465f46f8b12514
Showing with 4 additions and 5 deletions.
  1. +4 −5 Example/Classes/AFGowallaAPIClient.m
@@ -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;
}

0 comments on commit b681971

Please sign in to comment.