From cf963c06c388fb93ec99c6b0b7af09ea8658bc15 Mon Sep 17 00:00:00 2001 From: Eugene Dudnyk Date: Sun, 21 May 2017 12:49:03 +0200 Subject: [PATCH] #1909: Crash on multiple concurrent downloads when accessing self.URLOperations dictionary. --- SDWebImage/SDWebImageDownloader.m | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/SDWebImage/SDWebImageDownloader.m b/SDWebImage/SDWebImageDownloader.m index f6481612..bf7a6d94 100644 --- a/SDWebImage/SDWebImageDownloader.m +++ b/SDWebImage/SDWebImageDownloader.m @@ -230,11 +230,13 @@ __weak SDWebImageDownloaderOperation *woperation = operation; operation.completionBlock = ^{ - SDWebImageDownloaderOperation *soperation = woperation; - if (!soperation) return; - if (self.URLOperations[url] == soperation) { - [self.URLOperations removeObjectForKey:url]; - }; + dispatch_barrier_sync(self.barrierQueue, ^{ + SDWebImageDownloaderOperation *soperation = woperation; + if (!soperation) return; + if (self.URLOperations[url] == soperation) { + [self.URLOperations removeObjectForKey:url]; + }; + }); }; } id downloadOperationCancelToken = [operation addHandlersForProgress:progressBlock completed:completedBlock];