Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit b6819711167889944497f3144e465f46f8b12514 1 parent 8d9b7ac
Evan Long authored
Showing with 4 additions and 5 deletions.
  1. +4 −5 Example/Classes/AFGowallaAPIClient.m
View
9 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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.