From 1b8721792e823762a0a222ad49df6f08dfcc5ce6 Mon Sep 17 00:00:00 2001 From: Andy Himberger <3460697+ahimberg@users.noreply.github.com> Date: Sat, 10 Aug 2019 12:12:24 -0700 Subject: [PATCH] apple: fix timing issue crash in executeApplicationScript (#134) * fix timing issue with _reactInstance going away between null check and call * Move comment --- React/CxxBridge/RCTCxxBridge.mm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index 918b255de4..55c74ec96a 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -1302,19 +1302,21 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR [[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptWillStartExecutingNotification object:self->_parentBridge userInfo:@{@"bridge": self}]; + // TODO(OSS Candidate ISS#2710739) - use local reactInstance, instance can be null'd while constructing NSDataBigString + auto reactInstance = self->_reactInstance; if (isRAMBundle(script)) { [self->_performanceLogger markStartForTag:RCTPLRAMBundleLoad]; auto ramBundle = std::make_unique(sourceUrlStr.UTF8String); std::unique_ptr scriptStr = ramBundle->getStartupCode(); [self->_performanceLogger markStopForTag:RCTPLRAMBundleLoad]; [self->_performanceLogger setValue:scriptStr->size() forTag:RCTPLRAMStartupCodeSize]; - if (self->_reactInstance) { + if (reactInstance) { auto registry = RAMBundleRegistry::multipleBundlesRegistry(std::move(ramBundle), JSIndexedRAMBundle::buildFactory()); - self->_reactInstance->loadRAMBundle(std::move(registry), std::move(scriptStr), + reactInstance->loadRAMBundle(std::move(registry), std::move(scriptStr), sourceUrlStr.UTF8String, !async); } - } else if (self->_reactInstance) { - self->_reactInstance->loadScriptFromString(std::make_unique(script), 0, + } else if (reactInstance) { + reactInstance->loadScriptFromString(std::make_unique(script), 0, sourceUrlStr.UTF8String, !async, ""); // TODO(OSS Candidate ISS#2710739) } else { std::string methodName = async ? "loadApplicationScript" : "loadApplicationScriptSync";