From 7f39e5e60e76a99537733c8c8eef8c14b00890c5 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Sun, 2 Nov 2014 23:20:16 +0200 Subject: [PATCH] The code from SDWebImageDownloaderOperation connection:didFailWithError: should match the code from connectionDidFinishLoading:. This fixes #872 --- SDWebImage/SDWebImageDownloaderOperation.m | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index e0e5a13d..12c9751d 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -337,8 +337,7 @@ responseFromCached = NO; } - if (completionBlock) - { + if (completionBlock) { if (self.options & SDWebImageDownloaderIgnoreCachedResponse && responseFromCached) { completionBlock(nil, nil, nil, YES); } @@ -364,13 +363,17 @@ } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { - CFRunLoopStop(CFRunLoopGetCurrent()); - [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:nil]; + @synchronized(self) { + CFRunLoopStop(CFRunLoopGetCurrent()); + self.thread = nil; + self.connection = nil; + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:nil]; + } if (self.completedBlock) { self.completedBlock(nil, nil, error, YES); } - + self.completionBlock = nil; [self done]; }