From 608670ebed2f21bddf2433ae2a773ca4d0609ec0 Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Wed, 26 Dec 2018 11:08:21 -0800 Subject: [PATCH] iOS: guard against bad RCTModuleData instance Summary: In some rare race condition (usually involving network request handling vs bridge shutting down), there may be bad access to an RCTModuleData that may have been de-allocated. To prevent crashes, let's guard the access and return nil appropriately. Reviewed By: yungsters Differential Revision: D13548755 fbshipit-source-id: b97326524cd9ca70a13d15098a1eaadfc7f1a6a8 --- React/CxxBridge/RCTCxxBridge.mm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index 353bbce40..8ab1b7df5 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -458,6 +458,12 @@ struct RCTInstanceCallback : public InstanceCallback { RCTModuleData *moduleData = _moduleDataByName[moduleName]; if (moduleData) { + if (![moduleData isKindOfClass:[RCTModuleData class]]) { + // There is rare race condition where the data stored in the dictionary + // may have been deallocated, which means the module instance is no longer + // usable. + return nil; + } return moduleData.instance; }