mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Fix use-after-free race in RCTInstance callFunctionOnJSModule (#58816)
Summary: Pull Request resolved: https://github.com/react/react-native/pull/58816 ## Changelog: [Internal] Reviewed By: zeyap Differential Revision: D122831570 fbshipit-source-id: 924ffa228cadc454069b268a0fd1c1126953ba33
This commit is contained in:
1 parent
51e9a97775
commit
024b474ce9
1 file changed
+7
-3
+7
-3
@@ -171,10 +171,14 @@ using namespace facebook::react;
|
||||
|
||||
- (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args
|
||||
{
|
||||
if (_valid) {
|
||||
_reactInstance->callFunctionOnModule(
|
||||
[moduleName UTF8String], [method UTF8String], convertIdToFollyDynamic(args ? args : @[]));
|
||||
// This is called from arbitrary threads, while -invalidate destroys _reactInstance on
|
||||
// the JS thread, so checking _valid and dereferencing have to happen as one step.
|
||||
std::lock_guard<std::mutex> lock(_invalidationMutex);
|
||||
if (!_valid || !_reactInstance) {
|
||||
return;
|
||||
}
|
||||
_reactInstance->callFunctionOnModule(
|
||||
[moduleName UTF8String] ?: "", [method UTF8String] ?: "", convertIdToFollyDynamic(args ? args : @[]));
|
||||
}
|
||||
|
||||
- (void)invalidate
|
||||
|
||||
Reference in new issue
Block a user