@@ -335,48 +335,42 @@ - (UIImage *)scaledImageForKey:(NSString *)key image:(UIImage *)image {
335
335
}
336
336
337
337
- (void )connectionDidFinishLoading : (NSURLConnection *)aConnection {
338
- CFRunLoopStop (CFRunLoopGetCurrent ());
339
- self.connection = nil ;
340
-
341
- [[NSNotificationCenter defaultCenter ] postNotificationName: SDWebImageDownloadStopNotification object: nil ];
342
-
343
338
SDWebImageDownloaderCompletedBlock completionBlock = self.completedBlock ;
339
+ @synchronized (self) {
340
+ CFRunLoopStop (CFRunLoopGetCurrent ());
341
+ self.thread = nil ;
342
+ self.connection = nil ;
343
+ [[NSNotificationCenter defaultCenter ] postNotificationName: SDWebImageDownloadStopNotification object: nil ];
344
+ }
344
345
345
346
if (![[NSURLCache sharedURLCache ] cachedResponseForRequest: _request]) {
346
347
responseFromCached = NO ;
347
348
}
348
349
349
- if (completionBlock) {
350
+ if (completionBlock)
351
+ {
350
352
if (self.options & SDWebImageDownloaderIgnoreCachedResponse && responseFromCached) {
351
353
completionBlock (nil , nil , nil , YES );
352
- self.completionBlock = nil ;
353
- [self done ];
354
354
}
355
355
else {
356
-
357
356
UIImage *image = [UIImage sd_imageWithData: self .imageData];
358
-
359
357
NSString *key = [[SDWebImageManager sharedManager ] cacheKeyForURL: self .request.URL];
360
358
image = [self scaledImageForKey: key image: image];
361
-
362
- if (!image. images ) // Do not force decod animated GIFs
363
- {
359
+
360
+ // Do not force decoding animated GIFs
361
+ if (!image. images ) {
364
362
image = [UIImage decodedImageWithImage: image];
365
363
}
366
-
367
364
if (CGSizeEqualToSize (image.size , CGSizeZero)) {
368
365
completionBlock (nil , nil , [NSError errorWithDomain: @" SDWebImageErrorDomain" code: 0 userInfo: @{NSLocalizedDescriptionKey : @" Downloaded image has 0 pixels" }], YES );
369
366
}
370
367
else {
371
368
completionBlock (image, self.imageData , nil , YES );
372
369
}
373
- self.completionBlock = nil ;
374
- [self done ];
375
370
}
376
371
}
377
- else {
378
- [self done ];
379
- }
372
+ self.completionBlock = nil ;
373
+ [self done ];
380
374
}
381
375
382
376
- (void )connection : (NSURLConnection *)connection didFailWithError : (NSError *)error {
0 commit comments