Authored by robertmryan

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.
... ... @@ -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];
}];
... ...