iOS: Fix an image loader crash
iOS: Fix an image loader crash

Summary:
Fixes #10433

The code didn't account for the fact that cancelLoad is set by two different threads. It gets set on the URL request queue when the request completes successfully and it gets set on the UI queue during cancelation. This oversight lead to a couple of different kinds of crashes.

1. Attempt to invoke a nil function -- We check that cancelLoad is non-nil and on the next line we call it. However, cancelLoad could have been set to nil by the other thread between the time it was verified to be non-nil and the time it was called. Consequently, the program will attempt to call nil and crash.

2. Block deallocated while it's executing -- Suppose cancelLoad points to a block, it is verified to be non-nil, and it is successfully invoked. In the middle of executing the block, cancelLoad, the last reference to the block, is set to nil. This causes the block to be deallocated and its captured values to be freed. However, the block continues executing and the next time it attempts to use a captured value
Closes https://github.com/facebook/react-native/pull/11145

Differential Revision: D4261499

Pulled By: javache

fbshipit-source-id: 46424c6dd8cfa085cef32d945308de07798040bc

Purii/react-native,negativetwelve/react-native,tadeuzagallo/react-native,doochik/react-native,kesha-antonov/react-native,aaron-goshine/react-native,Andreyco/react-native,skevy/react-native,DannyvanderJagt/react-native,imDangerous/react-native,DannyvanderJagt/react-native,doochik/react-native,salanki/react-native,arthuralee/react-native,orenklein/react-native,thotegowda/react-native,clozr/react-native,negativetwelve/react-native,frantic/react-native,exponentjs/react-native,tadeuzagallo/react-native,jasonnoahchoi/react-native,ankitsinghania94/react-native,Guardiannw/react-native,myntra/react-native,hoastoolshop/react-native,dikaiosune/react-native,hoastoolshop/react-native,dikaiosune/react-native,ptomasroos/react-native,javache/react-native,makadaw/react-native,Livyli/react-native,gilesvangruisen/react-native,lprhodes/react-native,jasonnoahchoi/react-native,kesha-antonov/react-native,csatf/react-native,jevakallio/react-native,ndejesus1227/react-native,charlesvinette/react-native,imjerrybao/react-native,callstack-io/react-native,exponentjs/react-native,ptmt/react-native-macos,myntra/react-native,Purii/react-native,makadaw/react-native,orenklein/react-native,Bhullnatik/react-native,farazs/react-native,htc2u/react-native,peterp/react-native,Andreyco/react-native,kesha-antonov/react-native,pandiaraj44/react-native,Andreyco/react-native,ndejesus1227/react-native,janicduplessis/react-native,brentvatne/react-native,lprhodes/react-native,exponentjs/react-native,hoastoolshop/react-native,makadaw/react-native,arthuralee/react-native,tsjing/react-native,facebook/react-native,ptomasroos/react-native,Ehesp/react-native,pandiaraj44/react-native,happypancake/react-native,charlesvinette/react-native,chnfeeeeeef/react-native,satya164/react-native,imjerrybao/react-native,callstack-io/react-native,imDangerous/react-native,facebook/react-native,tszajna0/react-native,rickbeerendonk/react-native,aaron-goshine/react-native,kesha-antonov/react-native,jadbox/react-native,htc2u/react-native,eduardinni/react-native,alin23/react-native,esauter5/react-native,thotegowda/react-native,negativetwelve/react-native,makadaw/react-native,formatlos/react-native,CodeLinkIO/react-native,shrutic/react-native,farazs/react-native,shrutic/react-native,csatf/react-native,PlexChat/react-native,imDangerous/react-native,charlesvinette/react-native,javache/react-native,exponent/react-native,imjerrybao/react-native,formatlos/react-native,adamjmcgrath/react-native,jasonnoahchoi/react-native,hoangpham95/react-native,tsjing/react-native,tsjing/react-native,cpunion/react-native,imjerrybao/react-native,aljs/react-native,salanki/react-native,lprhodes/react-native,ankitsinghania94/react-native,Andreyco/react-native,facebook/react-native,thotegowda/react-native,cdlewis/react-native,jasonnoahchoi/react-native,aljs/react-native,cdlewis/react-native,myntra/react-native,satya164/react-native,farazs/react-native,shrutic/react-native,cpunion/react-native,janicduplessis/react-native,csatf/react-native,orenklein/react-native,brentvatne/react-native,salanki/react-native,formatlos/react-native,satya164/react-native,skevy/react-native,dikaiosune/react-native,janicduplessis/react-native,doochik/react-native,cdlewis/react-native,dikaiosune/react-native,forcedotcom/react-native,tadeuzagallo/react-native,pandiaraj44/react-native,negativetwelve/react-native,imDangerous/react-native,esauter5/react-native,peterp/react-native,esauter5/react-native,tsjing/react-native,shrutic/react-native,skevy/react-native,negativetwelve/react-native,salanki/react-native,Swaagie/react-native,formatlos/react-native,javache/react-native,jadbox/react-native,chnfeeeeeef/react-native,farazs/react-native,aaron-goshine/react-native,cpunion/react-native,tadeuzagallo/react-native,DannyvanderJagt/react-native,PlexChat/react-native,mironiasty/react-native,eduardinni/react-native,Purii/react-native,ptmt/react-native-macos,brentvatne/react-native,cdlewis/react-native,DanielMSchmidt/react-native,hammerandchisel/react-native,tsjing/react-native,exponent/react-native,Ehesp/react-native,happypancake/react-native,CodeLinkIO/react-native,jadbox/react-native,peterp/react-native,hoangpham95/react-native,negativetwelve/react-native,salanki/react-native,PlexChat/react-native,imDangerous/react-native,forcedotcom/react-native,satya164/react-native,clozr/react-native,hoangpham95/react-native,frantic/react-native,Bhullnatik/react-native,alin23/react-native,javache/react-native,ptomasroos/react-native,Bhullnatik/react-native,hoastoolshop/react-native,PlexChat/react-native,hoangpham95/react-native,DanielMSchmidt/react-native,ptmt/react-native-macos,hammerandchisel/react-native,callstack-io/react-native,janicduplessis/react-native,Purii/react-native,mironiasty/react-native,hammerandchisel/react-native,Swaagie/react-native,csatf/react-native,gilesvangruisen/react-native,hammerandchisel/react-native,negativetwelve/react-native,adamjmcgrath/react-native,aaron-goshine/react-native,frantic/react-native,lprhodes/react-native,shrutic123/react-native,brentvatne/react-native,brentvatne/react-native,formatlos/react-native,cdlewis/react-native,DanielMSchmidt/react-native,myntra/react-native,Swaagie/react-native,Livyli/react-native,kesha-antonov/react-native,cdlewis/react-native,Maxwell2022/react-native,ndejesus1227/react-native,javache/react-native,aaron-goshine/react-native,charlesvinette/react-native,Swaagie/react-native,brentvatne/react-native,aljs/react-native,brentvatne/react-native,happypancake/react-native,CodeLinkIO/react-native,dikaiosune/react-native,satya164/react-native,mironiasty/react-native,adamjmcgrath/react-native,DanielMSchmidt/react-native,frantic/react-native,tadeuzagallo/react-native,Ehesp/react-native,formatlos/react-native,htc2u/react-native,imDangerous/react-native,hoangpham95/react-native,rickbeerendonk/react-native,DannyvanderJagt/react-native,facebook/react-native,adamjmcgrath/react-native,gilesvangruisen/react-native,clozr/react-native,hoastoolshop/react-native,skevy/react-native,imDangerous/react-native,kesha-antonov/react-native,shrutic123/react-native,doochik/react-native,cpunion/react-native,farazs/react-native,csatf/react-native,facebook/react-native,makadaw/react-native,jadbox/react-native,hoangpham95/react-native,shrutic/react-native,shrutic123/react-native,Maxwell2022/react-native,skevy/react-native,Purii/react-native,janicduplessis/react-native,ankitsinghania94/react-native,lprhodes/react-native,ptmt/react-native-macos,pandiaraj44/react-native,imjerrybao/react-native,htc2u/react-native,exponentjs/react-native,tadeuzagallo/react-native,hoastoolshop/react-native,chnfeeeeeef/react-native,imjerrybao/react-native,doochik/react-native,frantic/react-native,imjerrybao/react-native,shrutic/react-native,pandiaraj44/react-native,kesha-antonov/react-native,Guardiannw/react-native,htc2u/react-native,chnfeeeeeef/react-native,hammerandchisel/react-native,Livyli/react-native,farazs/react-native,Swaagie/react-native,esauter5/react-native,exponentjs/react-native,tszajna0/react-native,hoastoolshop/react-native,peterp/react-native,aaron-goshine/react-native,htc2u/react-native,orenklein/react-native,shrutic/react-native,forcedotcom/react-native,cdlewis/react-native,DannyvanderJagt/react-native,Maxwell2022/react-native,Livyli/react-native,thotegowda/react-native,adamjmcgrath/react-native,arthuralee/react-native,Livyli/react-native,rickbeerendonk/react-native,happypancake/react-native,exponentjs/react-native,cpunion/react-native,cpunion/react-native,thotegowda/react-native,formatlos/react-native,orenklein/react-native,Bhullnatik/react-native,formatlos/react-native,Bhullnatik/react-native,hoangpham95/react-native,DanielMSchmidt/react-native,ndejesus1227/react-native,peterp/react-native,tszajna0/react-native,ptomasroos/react-native,rickbeerendonk/react-native,forcedotcom/react-native,DannyvanderJagt/react-native,PlexChat/react-native,tadeuzagallo/react-native,Guardiannw/react-native,eduardinni/react-native,jevakallio/react-native,happypancake/react-native,gilesvangruisen/react-native,mironiasty/react-native,tszajna0/react-native,alin23/react-native,aljs/react-native,clozr/react-native,rickbeerendonk/react-native,ankitsinghania94/react-native,pandiaraj44/react-native,aljs/react-native,hammerandchisel/react-native,jevakallio/react-native,Andreyco/react-native,DannyvanderJagt/react-native,orenklein/react-native,peterp/react-native,tadeuzagallo/react-native,shrutic/react-native,jevakallio/react-native,alin23/react-native,jadbox/react-native,Maxwell2022/react-native,Ehesp/react-native,myntra/react-native,skevy/react-native,charlesvinette/react-native,myntra/react-native,gilesvangruisen/react-native,Swaagie/react-native,chnfeeeeeef/react-native,mironiasty/react-native,ptomasroos/react-native,exponent/react-native,esauter5/react-native,happypancake/react-native,CodeLinkIO/react-native,CodeLinkIO/react-native,exponent/react-native,PlexChat/react-native,Guardiannw/react-native,peterp/react-native,Bhullnatik/react-native,hammerandchisel/react-native,myntra/react-native,kesha-antonov/react-native,Maxwell2022/react-native,Swaagie/react-native,javache/react-native,ptmt/react-native-macos,esauter5/react-native,clozr/react-native,Ehesp/react-native,arthuralee/react-native,adamjmcgrath/react-native,tsjing/react-native,farazs/react-native,jevakallio/react-native,javache/react-native,hammerandchisel/react-native,Swaagie/react-native,csatf/react-native,DanielMSchmidt/react-native,janicduplessis/react-native,csatf/react-native,aljs/react-native,exponent/react-native,CodeLinkIO/react-native,aaron-goshine/react-native,ankitsinghania94/react-native,callstack-io/react-native,shrutic123/react-native,lprhodes/react-native,callstack-io/react-native,Guardiannw/react-native,mironiasty/react-native,facebook/react-native,negativetwelve/react-native,adamjmcgrath/react-native,makadaw/react-native,DannyvanderJagt/react-native,Guardiannw/react-native,alin23/react-native,clozr/react-native,eduardinni/react-native,charlesvinette/react-native,forcedotcom/react-native,Bhullnatik/react-native,alin23/react-native,rickbeerendonk/react-native,satya164/react-native,Andreyco/react-native,exponent/react-native,doochik/react-native,brentvatne/react-native,jadbox/react-native,Purii/react-native,gilesvangruisen/react-native,forcedotcom/react-native,Guardiannw/react-native,Purii/react-native,makadaw/react-native,pandiaraj44/react-native,charlesvinette/react-native,Livyli/react-native,forcedotcom/react-native,DanielMSchmidt/react-native,DanielMSchmidt/react-native,ankitsinghania94/react-native,clozr/react-native,orenklein/react-native,Purii/react-native,rickbeerendonk/react-native,chnfeeeeeef/react-native,callstack-io/react-native,CodeLinkIO/react-native,facebook/react-native,eduardinni/react-native,happypancake/react-native,htc2u/react-native,CodeLinkIO/react-native,satya164/react-native,Ehesp/react-native,hoastoolshop/react-native,ptomasroos/react-native,myntra/react-native,PlexChat/react-native,tszajna0/react-native,chnfeeeeeef/react-native,makadaw/react-native,exponentjs/react-native,jevakallio/react-native,ptmt/react-native-macos,satya164/react-native,doochik/react-native,peterp/react-native,jasonnoahchoi/react-native,aaron-goshine/react-native,Bhullnatik/react-native,ptmt/react-native-macos,mironiasty/react-native,orenklein/react-native,cdlewis/react-native,adamjmcgrath/react-native,ptomasroos/react-native,janicduplessis/react-native,mironiasty/react-native,Andreyco/react-native,dikaiosune/react-native,eduardinni/react-native,thotegowda/react-native,cdlewis/react-native,clozr/react-native,alin23/react-native,janicduplessis/react-native,Guardiannw/react-native,skevy/react-native,dikaiosune/react-native,brentvatne/react-native,salanki/react-native,tszajna0/react-native,facebook/react-native,negativetwelve/react-native,kesha-antonov/react-native,ndejesus1227/react-native,jevakallio/react-native,Andreyco/react-native,jasonnoahchoi/react-native,rickbeerendonk/react-native,imDangerous/react-native,eduardinni/react-native,hoangpham95/react-native,arthuralee/react-native,ptmt/react-native-macos,Maxwell2022/react-native,jevakallio/react-native,esauter5/react-native,Livyli/react-native,skevy/react-native,gilesvangruisen/react-native,pandiaraj44/react-native,Maxwell2022/react-native,ndejesus1227/react-native,imjerrybao/react-native,gilesvangruisen/react-native,thotegowda/react-native,shrutic123/react-native,ndejesus1227/react-native,Ehesp/react-native,htc2u/react-native,lprhodes/react-native,rickbeerendonk/react-native,thotegowda/react-native,salanki/react-native,dikaiosune/react-native,exponent/react-native,shrutic123/react-native,happypancake/react-native,ankitsinghania94/react-native,tsjing/react-native,PlexChat/react-native,callstack-io/react-native,forcedotcom/react-native,charlesvinette/react-native,shrutic123/react-native,aljs/react-native,farazs/react-native,Maxwell2022/react-native,makadaw/react-native,mironiasty/react-native,ndejesus1227/react-native,esauter5/react-native,alin23/react-native,javache/react-native,tsjing/react-native,exponentjs/react-native,shrutic123/react-native,exponent/react-native,jevakallio/react-native,ankitsinghania94/react-native,ptomasroos/react-native,callstack-io/react-native,lprhodes/react-native,eduardinni/react-native,Ehesp/react-native,cpunion/react-native,tszajna0/react-native,aljs/react-native,facebook/react-native,csatf/react-native,chnfeeeeeef/react-native,javache/react-native,farazs/react-native,jasonnoahchoi/react-native,doochik/react-native,jasonnoahchoi/react-native,doochik/react-native,Livyli/react-native,cpunion/react-native,salanki/react-native,jadbox/react-native,tszajna0/react-native,jadbox/react-native,formatlos/react-native,myntra/react-native