Skip to content

Commit 9aec26c

Browse files
DevmateRemedimateMacaClaude Botfacebook-github-bot
authored andcommitted
Fix use-after-free data race in EventEmitter.cpp (T259167206)
Reviewed By: javache Differential Revision: D104028371
1 parent c0bf154 commit 9aec26c

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

packages/react-native/ReactCommon/react/renderer/core/EventEmitter.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,19 @@ void EventEmitter::dispatchEvent(
134134
return;
135135
}
136136

137+
SharedEventTarget eventTarget;
138+
std::weak_ptr<const ShadowNodeFamily> shadowNodeFamily;
139+
{
140+
std::scoped_lock lock(DispatchMutex());
141+
eventTarget = eventTarget_;
142+
shadowNodeFamily = shadowNodeFamily_;
143+
}
144+
137145
eventDispatcher->dispatchEvent(RawEvent(
138146
normalizeEventType(std::move(type)),
139147
std::move(payload),
140-
eventTarget_,
141-
shadowNodeFamily_,
148+
std::move(eventTarget),
149+
std::move(shadowNodeFamily),
142150
category,
143151
false,
144152
eventTimestamp));
@@ -180,11 +188,19 @@ void EventEmitter::dispatchUniqueEvent(
180188
return;
181189
}
182190

191+
SharedEventTarget eventTarget;
192+
std::weak_ptr<const ShadowNodeFamily> shadowNodeFamily;
193+
{
194+
std::scoped_lock lock(DispatchMutex());
195+
eventTarget = eventTarget_;
196+
shadowNodeFamily = shadowNodeFamily_;
197+
}
198+
183199
eventDispatcher->dispatchUniqueEvent(RawEvent(
184200
normalizeEventType(std::move(type)),
185201
std::move(payload),
186-
eventTarget_,
187-
shadowNodeFamily_,
202+
std::move(eventTarget),
203+
std::move(shadowNodeFamily),
188204
RawEvent::Category::Continuous,
189205
true,
190206
eventTimestamp));

0 commit comments

Comments
 (0)