Skip to content

Commit

Permalink
iOS: guard against bad RCTModuleData instance
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fkgozali authored and facebook-github-bot committed Dec 26, 2018
1 parent 010e330 commit 608670e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,12 @@ - (id)moduleForName:(NSString *)moduleName lazilyLoadIfNecessary:(BOOL)lazilyLoa

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;
}

Expand Down

0 comments on commit 608670e

Please sign in to comment.