Skip to content

Commit

Permalink
Pulling in image crash fixes facebook#10473 facebook#11145
Browse files Browse the repository at this point in the history
  • Loading branch information
Tj authored and Tj committed Jan 5, 2017
1 parent 5ee88d4 commit 201198b
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions Libraries/Image/RCTImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,14 @@ - (void)dequeueTasks
{
dispatch_async(_URLRequestQueue, ^{
// Remove completed tasks
NSMutableArray *tasksToRemove = nil;
for (RCTNetworkTask *task in self->_pendingTasks.reverseObjectEnumerator) {
switch (task.status) {
case RCTNetworkTaskFinished:
[self->_pendingTasks removeObject:task];
if (!tasksToRemove) {
tasksToRemove = [NSMutableArray new];
}
[tasksToRemove addObject:task];
self->_activeTasks--;
break;
case RCTNetworkTaskPending:
Expand All @@ -248,14 +252,21 @@ - (void)dequeueTasks
// Check task isn't "stuck"
if (task.requestToken == nil) {
RCTLogWarn(@"Task orphaned for request %@", task.request);
[self->_pendingTasks removeObject:task];
if (!tasksToRemove) {
tasksToRemove = [NSMutableArray new];
}
[tasksToRemove addObject:task];
self->_activeTasks--;
[task cancel];
}
break;
}
}

if (tasksToRemove) {
[self->_pendingTasks removeObjectsInArray:tasksToRemove];
}

// Start queued decode
NSInteger activeDecodes = self->_scheduledDecodes - self->_pendingDecodes.count;
while (activeDecodes == 0 || (self->_activeBytes <= self->_maxConcurrentDecodingBytes &&
Expand Down Expand Up @@ -378,9 +389,10 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
});

return ^{
if (cancelLoad) {
cancelLoad();
cancelLoad = nil;
dispatch_block_t cancelLoadLocal = cancelLoad;
cancelLoad = nil;
if (cancelLoadLocal && !cancelled) {
cancelLoadLocal();
}
OSAtomicOr32Barrier(1, &cancelled);
};
Expand Down Expand Up @@ -496,8 +508,9 @@ - (RCTImageLoaderCancellationBlock)loadImageWithURLRequest:(NSURLRequest *)image
__block volatile uint32_t cancelled = 0;
__block dispatch_block_t cancelLoad = nil;
dispatch_block_t cancellationBlock = ^{
if (cancelLoad) {
cancelLoad();
dispatch_block_t cancelLoadLocal = cancelLoad;
if (cancelLoadLocal && !cancelled) {
cancelLoadLocal();
}
OSAtomicOr32Barrier(1, &cancelled);
};
Expand Down

0 comments on commit 201198b

Please sign in to comment.