Skip to content

Commit

Permalink
FIX #9751 - Cancelling offscreen image loads causing crashes
Browse files Browse the repository at this point in the history
Summary:
This fixes #9751

We were seeing the same issues as the original reporter.

I'm not an expert on this code, so apologies if it's naive, but we haven't seen the crash since making this change.

From my understanding of it, it seems like the `cancelLoad` block was being released before the block returned by `_loadImageOrDataWithURLRequest:` was called.
This PR checks the `cancelled` flag before calling `cancelLoad()`.
Closes #10016

Differential Revision: D3902723

Pulled By: javache

fbshipit-source-id: 75cd115e28694105c6fc29469986998ca0d4cd09
  • Loading branch information
tobycox authored and Facebook Github Bot 0 committed Sep 21, 2016
1 parent 820b1c0 commit 1a62b66
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Libraries/Image/RCTImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ - (RCTImageLoaderCancellationBlock)_loadImageOrDataWithURLRequest:(NSURLRequest
});

return ^{
if (cancelLoad) {
if (cancelLoad && !cancelled) {
cancelLoad();
cancelLoad = nil;
}
Expand Down

1 comment on commit 1a62b66

@jmcginty
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same pattern is repeated at line 500, I think you need to add the same fix here.

  dispatch_block_t cancellationBlock = ^{
    if (cancelLoad) {
      cancelLoad();
    }
    OSAtomicOr32Barrier(1, &cancelled);
};

Please sign in to comment.