Skip to content

Commit b85556f

Browse files
Charlie SavageOlivier Poitrey
Charlie Savage
authored and
Olivier Poitrey
committed
This is an attempt to avoid the crashes in SDWebImage#341.
It won't fix the underlying issue but I hope it will avoid it in most cases. The various crash reports indicate the underlying download operation is being freed before the async block in dataReceived is being executed. This fix change tries to avoid every calling the async block.
1 parent 1162585 commit b85556f

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

SDWebImage/SDWebImageDownloaderOperation.m

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,7 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon
160160
self.progressBlock(0, expected);
161161
}
162162

163-
dispatch_async(self.queue, ^
164-
{
165-
self.imageData = [NSMutableData.alloc initWithCapacity:expected];
166-
});
163+
self.imageData = [NSMutableData.alloc initWithCapacity:expected];
167164
}
168165
else
169166
{
@@ -182,11 +179,11 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon
182179

183180
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
184181
{
185-
dispatch_async(self.queue, ^
186-
{
187-
[self.imageData appendData:data];
182+
[self.imageData appendData:data];
188183

189-
if ((self.options & SDWebImageDownloaderProgressiveDownload) && self.expectedSize > 0 && self.completedBlock)
184+
if ((self.options & SDWebImageDownloaderProgressiveDownload) && self.expectedSize > 0 && self.completedBlock)
185+
{
186+
dispatch_async(self.queue, ^
190187
{
191188
// The following code is from http://www.cocoaintheshell.com/2011/05/progressive-images-download-imageio/
192189
// Thanks to the author @Nyx0uf
@@ -254,7 +251,8 @@ - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
254251
}
255252

256253
CFRelease(imageSource);
257-
}
254+
});
255+
258256
NSUInteger received = self.imageData.length;
259257
dispatch_async(dispatch_get_main_queue(), ^
260258
{
@@ -263,7 +261,7 @@ - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
263261
self.progressBlock(received, self.expectedSize);
264262
}
265263
});
266-
});
264+
}
267265
}
268266

269267
- (void)connectionDidFinishLoading:(NSURLConnection *)aConnection

0 commit comments

Comments
 (0)