From 9d6d39de86057f92d41a9f7eed7fdddf1ac09582 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Fri, 29 May 2020 20:36:05 -0700 Subject: [PATCH] A corner case check in `Instance::handleMemoryPressure` Summary: At some early stages of Instance initialization, it does not have a `nativeToJsBridge_`. At the same time, `handleMemoryPressure` can be called at any point in time, so we should check the pointer for not being null before calling on it. Changelog: [Internal] Fabric-specific internal change. Reviewed By: JoshuaGross, mdvacca Differential Revision: D21798522 fbshipit-source-id: 6384da88784cceb493cf9810408cbb47777d3f4b --- ReactCommon/cxxreact/Instance.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ReactCommon/cxxreact/Instance.cpp b/ReactCommon/cxxreact/Instance.cpp index d5b4af5e515..2f2dc5d448d 100644 --- a/ReactCommon/cxxreact/Instance.cpp +++ b/ReactCommon/cxxreact/Instance.cpp @@ -222,7 +222,11 @@ ModuleRegistry &Instance::getModuleRegistry() { } void Instance::handleMemoryPressure(int pressureLevel) { - nativeToJsBridge_->handleMemoryPressure(pressureLevel); + if (nativeToJsBridge_) { + // This class resets `nativeToJsBridge_` only in the destructor, + // hence a race is not possible there. + nativeToJsBridge_->handleMemoryPressure(pressureLevel); + } } std::shared_ptr Instance::getJSCallInvoker() {