diff --git a/Libraries/Blob/RCTBlobPlugins.mm b/Libraries/Blob/RCTBlobPlugins.mm index d06f40e5d21120..289094f35d43a0 100644 --- a/Libraries/Blob/RCTBlobPlugins.mm +++ b/Libraries/Blob/RCTBlobPlugins.mm @@ -17,13 +17,14 @@ #import Class RCTBlobClassProvider(const char *name) { - static std::unordered_map sCoreModuleClassMap = { + // Intentionally leak to avoid crashing after static destructors are run. + static const auto sCoreModuleClassMap = new const std::unordered_map{ {"FileReaderModule", RCTFileReaderModuleCls}, {"BlobModule", RCTBlobManagerCls}, }; - auto p = sCoreModuleClassMap.find(name); - if (p != sCoreModuleClassMap.end()) { + auto p = sCoreModuleClassMap->find(name); + if (p != sCoreModuleClassMap->end()) { auto classFunc = p->second; return classFunc(); } diff --git a/Libraries/Image/RCTImagePlugins.mm b/Libraries/Image/RCTImagePlugins.mm index 3cde9e95650e5b..1e03e76066e244 100644 --- a/Libraries/Image/RCTImagePlugins.mm +++ b/Libraries/Image/RCTImagePlugins.mm @@ -17,7 +17,8 @@ #import Class RCTImageClassProvider(const char *name) { - static std::unordered_map sCoreModuleClassMap = { + // Intentionally leak to avoid crashing after static destructors are run. + static const auto sCoreModuleClassMap = new const std::unordered_map{ {"GIFImageDecoder", RCTGIFImageDecoderCls}, {"ImageEditingManager", RCTImageEditingManagerCls}, {"ImageLoader", RCTImageLoaderCls}, @@ -25,8 +26,8 @@ Class RCTImageClassProvider(const char *name) { {"LocalAssetImageLoader", RCTLocalAssetImageLoaderCls}, }; - auto p = sCoreModuleClassMap.find(name); - if (p != sCoreModuleClassMap.end()) { + auto p = sCoreModuleClassMap->find(name); + if (p != sCoreModuleClassMap->end()) { auto classFunc = p->second; return classFunc(); } diff --git a/Libraries/LinkingIOS/RCTLinkingPlugins.mm b/Libraries/LinkingIOS/RCTLinkingPlugins.mm index b2549557558b23..b5993a9b306ff5 100644 --- a/Libraries/LinkingIOS/RCTLinkingPlugins.mm +++ b/Libraries/LinkingIOS/RCTLinkingPlugins.mm @@ -17,12 +17,13 @@ #import Class RCTLinkingClassProvider(const char *name) { - static std::unordered_map sCoreModuleClassMap = { + // Intentionally leak to avoid crashing after static destructors are run. + static const auto sCoreModuleClassMap = new const std::unordered_map{ {"LinkingManager", RCTLinkingManagerCls}, }; - auto p = sCoreModuleClassMap.find(name); - if (p != sCoreModuleClassMap.end()) { + auto p = sCoreModuleClassMap->find(name); + if (p != sCoreModuleClassMap->end()) { auto classFunc = p->second; return classFunc(); } diff --git a/Libraries/NativeAnimation/RCTAnimationPlugins.mm b/Libraries/NativeAnimation/RCTAnimationPlugins.mm index 6b9768b5257e10..b0eecfc9b8826a 100644 --- a/Libraries/NativeAnimation/RCTAnimationPlugins.mm +++ b/Libraries/NativeAnimation/RCTAnimationPlugins.mm @@ -17,13 +17,14 @@ #import Class RCTAnimationClassProvider(const char *name) { - static std::unordered_map sCoreModuleClassMap = { + // Intentionally leak to avoid crashing after static destructors are run. + static const auto sCoreModuleClassMap = new const std::unordered_map{ {"NativeAnimatedModule", RCTNativeAnimatedModuleCls}, {"NativeAnimatedTurboModule", RCTNativeAnimatedTurboModuleCls}, }; - auto p = sCoreModuleClassMap.find(name); - if (p != sCoreModuleClassMap.end()) { + auto p = sCoreModuleClassMap->find(name); + if (p != sCoreModuleClassMap->end()) { auto classFunc = p->second; return classFunc(); } diff --git a/Libraries/Network/RCTNetworkPlugins.mm b/Libraries/Network/RCTNetworkPlugins.mm index 6a00252c5679b8..f1a016e1d209c8 100644 --- a/Libraries/Network/RCTNetworkPlugins.mm +++ b/Libraries/Network/RCTNetworkPlugins.mm @@ -17,15 +17,16 @@ #import Class RCTNetworkClassProvider(const char *name) { - static std::unordered_map sCoreModuleClassMap = { + // Intentionally leak to avoid crashing after static destructors are run. + static const auto sCoreModuleClassMap = new const std::unordered_map{ {"Networking", RCTNetworkingCls}, {"DataRequestHandler", RCTDataRequestHandlerCls}, {"FileRequestHandler", RCTFileRequestHandlerCls}, {"HTTPRequestHandler", RCTHTTPRequestHandlerCls}, }; - auto p = sCoreModuleClassMap.find(name); - if (p != sCoreModuleClassMap.end()) { + auto p = sCoreModuleClassMap->find(name); + if (p != sCoreModuleClassMap->end()) { auto classFunc = p->second; return classFunc(); } diff --git a/Libraries/PushNotificationIOS/RCTPushNotificationPlugins.mm b/Libraries/PushNotificationIOS/RCTPushNotificationPlugins.mm index 587a7b17a86688..434829371738ec 100644 --- a/Libraries/PushNotificationIOS/RCTPushNotificationPlugins.mm +++ b/Libraries/PushNotificationIOS/RCTPushNotificationPlugins.mm @@ -17,12 +17,13 @@ #import Class RCTPushNotificationClassProvider(const char *name) { - static std::unordered_map sCoreModuleClassMap = { + // Intentionally leak to avoid crashing after static destructors are run. + static const auto sCoreModuleClassMap = new const std::unordered_map{ {"PushNotificationManager", RCTPushNotificationManagerCls}, }; - auto p = sCoreModuleClassMap.find(name); - if (p != sCoreModuleClassMap.end()) { + auto p = sCoreModuleClassMap->find(name); + if (p != sCoreModuleClassMap->end()) { auto classFunc = p->second; return classFunc(); } diff --git a/Libraries/Settings/RCTSettingsPlugins.mm b/Libraries/Settings/RCTSettingsPlugins.mm index 09438ed1fc31f3..7ce46c64c84a4d 100644 --- a/Libraries/Settings/RCTSettingsPlugins.mm +++ b/Libraries/Settings/RCTSettingsPlugins.mm @@ -17,12 +17,13 @@ #import Class RCTSettingsClassProvider(const char *name) { - static std::unordered_map sCoreModuleClassMap = { + // Intentionally leak to avoid crashing after static destructors are run. + static const auto sCoreModuleClassMap = new const std::unordered_map{ {"SettingsManager", RCTSettingsManagerCls}, }; - auto p = sCoreModuleClassMap.find(name); - if (p != sCoreModuleClassMap.end()) { + auto p = sCoreModuleClassMap->find(name); + if (p != sCoreModuleClassMap->end()) { auto classFunc = p->second; return classFunc(); } diff --git a/Libraries/Vibration/RCTVibrationPlugins.mm b/Libraries/Vibration/RCTVibrationPlugins.mm index 61421c2ef21e1c..d98ae4aae82b57 100644 --- a/Libraries/Vibration/RCTVibrationPlugins.mm +++ b/Libraries/Vibration/RCTVibrationPlugins.mm @@ -17,12 +17,13 @@ #import Class RCTVibrationClassProvider(const char *name) { - static std::unordered_map sCoreModuleClassMap = { + // Intentionally leak to avoid crashing after static destructors are run. + static const auto sCoreModuleClassMap = new const std::unordered_map{ {"Vibration", RCTVibrationCls}, }; - auto p = sCoreModuleClassMap.find(name); - if (p != sCoreModuleClassMap.end()) { + auto p = sCoreModuleClassMap->find(name); + if (p != sCoreModuleClassMap->end()) { auto classFunc = p->second; return classFunc(); } diff --git a/React/CoreModules/CoreModulesPlugins.mm b/React/CoreModules/CoreModulesPlugins.mm index c2d1b268b4fa6a..42ba5e45c9ecf5 100644 --- a/React/CoreModules/CoreModulesPlugins.mm +++ b/React/CoreModules/CoreModulesPlugins.mm @@ -17,7 +17,8 @@ #import Class RCTCoreModulesClassProvider(const char *name) { - static std::unordered_map sCoreModuleClassMap = { + // Intentionally leak to avoid crashing after static destructors are run. + static const auto sCoreModuleClassMap = new const std::unordered_map{ {"AccessibilityManager", RCTAccessibilityManagerCls}, {"Appearance", RCTAppearanceCls}, {"DeviceInfo", RCTDeviceInfoCls}, @@ -45,8 +46,8 @@ Class RCTCoreModulesClassProvider(const char *name) { {"EventDispatcher", RCTEventDispatcherCls}, }; - auto p = sCoreModuleClassMap.find(name); - if (p != sCoreModuleClassMap.end()) { + auto p = sCoreModuleClassMap->find(name); + if (p != sCoreModuleClassMap->end()) { auto classFunc = p->second; return classFunc(); } diff --git a/React/CxxModule/RCTNativeModule.mm b/React/CxxModule/RCTNativeModule.mm index be74794fc572c0..cea144f5f469da 100644 --- a/React/CxxModule/RCTNativeModule.mm +++ b/React/CxxModule/RCTNativeModule.mm @@ -100,7 +100,9 @@ static MethodCallResult invokeInner( #else (void)(callId); #endif - invokeInner(weakBridge, weakModuleData, methodId, std::move(params), callId, isSyncModule ? Sync : Async); + @autoreleasepool { + invokeInner(weakBridge, weakModuleData, methodId, std::move(params), callId, isSyncModule ? Sync : Async); + } }; if (isSyncModule) {