Explorar el Código

Replaced #1537 - fixed a potential retain cycle in `SDWebImageManager`.

Bogdan Poplauschi hace 9 años
padre
commit
9cd6779
Se han modificado 1 ficheros con 3 adiciones y 2 borrados
  1. 3 2
      SDWebImage/SDWebImageManager.m

+ 3 - 2
SDWebImage/SDWebImageManager.m

@@ -168,7 +168,7 @@
                 // ignore image read from NSURLCache if image if cached but force refreshing
                 downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
             }
-            id subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *downloadedData, NSError *error, BOOL finished) {
+            SDWebImageDownloadToken *subOperationToken = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *downloadedData, NSError *error, BOOL finished) {
                 __strong __typeof(weakOperation) strongOperation = weakOperation;
                 if (!strongOperation || strongOperation.isCancelled) {
                     // Do nothing if the operation was cancelled
@@ -224,8 +224,9 @@
                     [self safelyRemoveOperationFromRunning:strongOperation];
                 }
             }];
+            __weak typeof(subOperationToken)weakSubOperationToken = subOperationToken;
             operation.cancelBlock = ^{
-                [self.imageDownloader cancel:subOperation];
+                [self.imageDownloader cancel:weakSubOperationToken];
                 __strong __typeof(weakOperation) strongOperation = weakOperation;
                 [self safelyRemoveOperationFromRunning:strongOperation];
             };