From a46f6149e502862ef8b8b02a39a8df118dea3f3c Mon Sep 17 00:00:00 2001 From: robertmryan Date: Wed, 11 Jun 2014 02:14:40 -0400 Subject: [PATCH] Resolve race condition. While exceedingly unlikely, the old construct introduced potential race condition where it checked wself first, and assigned sself second. This now assigns sself first, and then checks that, which is the correct pattern, already used elsewhere in SDWebImage. --- SDWebImage/SDWebImageDownloader.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SDWebImage/SDWebImageDownloader.m b/SDWebImage/SDWebImageDownloader.m index 09ceb4f..251bc51 100644 --- a/SDWebImage/SDWebImageDownloader.m +++ b/SDWebImage/SDWebImageDownloader.m @@ -127,8 +127,8 @@ static NSString *const kCompletedCallbackKey = @"completed"; operation = [[SDWebImageDownloaderOperation alloc] initWithRequest:request options:options progress:^(NSInteger receivedSize, NSInteger expectedSize) { - if (!wself) return; SDWebImageDownloader *sself = wself; + if (!sself) return; NSArray *callbacksForURL = [sself callbacksForURL:url]; for (NSDictionary *callbacks in callbacksForURL) { SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey]; @@ -136,8 +136,8 @@ static NSString *const kCompletedCallbackKey = @"completed"; } } completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) { - if (!wself) return; SDWebImageDownloader *sself = wself; + if (!sself) return; NSArray *callbacksForURL = [sself callbacksForURL:url]; if (finished) { [sself removeCallbacksForURL:url]; @@ -148,8 +148,8 @@ static NSString *const kCompletedCallbackKey = @"completed"; } } cancelled:^{ - if (!wself) return; SDWebImageDownloader *sself = wself; + if (!sself) return; [sself removeCallbacksForURL:url]; }];