Fixed a leak of AFHTTPRequestOperation in setCompletionBlock:

- Added a block object to reference self in the completion block
- Added a pointer to the onceToken to be used in the completion block
This commit is contained in:
Patrick Hernandez 2012-04-14 15:16:14 -05:00
parent 673e70525a
commit 3263f06edb

View file

@ -203,13 +203,16 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
} }
- (void)setCompletionBlock:(void (^)(void))block { - (void)setCompletionBlock:(void (^)(void))block {
__block AFHTTPRequestOperation *blockSelf = self;
dispatch_once_t *blockOnceToken = &_onceToken;
[super setCompletionBlock:^{ [super setCompletionBlock:^{
if(block) { if(block) {
block(); block();
} }
// Dispatch once is used to ensure that setting the block with this block will not cause multiple calls to 'dispatch_group_leave' // Dispatch once is used to ensure that setting the block with this block will not cause multiple calls to 'dispatch_group_leave'
dispatch_once(&_onceToken, ^{ dispatch_once(blockOnceToken, ^{
dispatch_group_leave(self.dispatchGroup); dispatch_group_leave(blockSelf.dispatchGroup);
}); });
}]; }];
} }