Skip to content

Commit

Permalink
Fix use-after-free in AsyncEventBeat (#43618)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #43618

Both common and Android implementations of AsyncEventBeat use weak_ptrs
to determine if the object is still valid before invoking the callback.
Move the write to `isBeatCallbackScheduled_` down so it's protected by
that same check.

Changelog: [Internal]

Reviewed By: javache, NickGerleman

Differential Revision: D55226529

fbshipit-source-id: 9e2a34369346d11dcea69d120dfa5935320f9ba1
  • Loading branch information
tnovak authored and facebook-github-bot committed Mar 26, 2024
1 parent ac714b1 commit 00725fa
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ void AsyncEventBeat::tick() const {
isBeatCallbackScheduled_ = true;

runtimeExecutor_([this, ownerBox = ownerBox_](jsi::Runtime& runtime) {
isBeatCallbackScheduled_ = false;
auto owner = ownerBox->owner.lock();
if (!owner) {
return;
}

isBeatCallbackScheduled_ = false;
if (beatCallback_) {
beatCallback_(runtime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ void AsynchronousEventBeat::induce() const {
isBeatCallbackScheduled_ = true;

runtimeExecutor_([this, weakOwner](jsi::Runtime& runtime) {
isBeatCallbackScheduled_ = false;

auto owner = weakOwner.lock();
if (!owner) {
return;
}

isBeatCallbackScheduled_ = false;
if (beatCallback_) {
beatCallback_(runtime);
}
Expand Down

0 comments on commit 00725fa

Please sign in to comment.