Use module copies in RCTBridge APIs

Summary: This array can be modified while it's being iterated, so we need to take a copy. I also found another crash and guarded against it.

Reviewed By: fkgozali

Differential Revision: D8955708

fbshipit-source-id: 76250bc5d451776e74505733c0f3c14e555fb576
This commit is contained in:
Mehdi Mulani 2018-07-23 14:44:20 -07:00 committed by Facebook Github Bot
parent ccdd450b12
commit 3d8b83927b
2 changed files with 4 additions and 3 deletions

View File

@ -246,7 +246,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
- (NSArray *)modulesConformingToProtocol:(Protocol *)protocol
{
NSMutableArray *modules = [NSMutableArray new];
for (Class moduleClass in self.moduleClasses) {
for (Class moduleClass in [self.moduleClasses copy]) {
if ([moduleClass conformsToProtocol:protocol]) {
id module = [self moduleForClass:moduleClass];
if (module) {

View File

@ -544,8 +544,9 @@ struct RCTInstanceCallback : public InstanceCallback {
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways,
@"-[RCTCxxBridge initModulesWithDispatchGroup:] autoexported moduleData", nil);
NSMutableArray<RCTModuleData *> *moduleDataByID = [NSMutableArray arrayWithCapacity:moduleClasses.count];
for (Class moduleClass in moduleClasses) {
NSArray *moduleClassesCopy = [moduleClasses copy];
NSMutableArray<RCTModuleData *> *moduleDataByID = [NSMutableArray arrayWithCapacity:moduleClassesCopy.count];
for (Class moduleClass in moduleClassesCopy) {
NSString *moduleName = RCTBridgeModuleNameForClass(moduleClass);
// Check for module name collisions