From 659712b475025bda1a534bf3db094e77411b2014 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Wed, 28 Feb 2024 11:33:54 -0800 Subject: [PATCH] Destroy SessionState only after destroying HostAgent Summary: Changelog: [Internal] Fixes a bug detected by LeakSanitizer: `HostAgent`'s destructor writes to session state, but when the containing `HostTargetSession` is being torn down, the `SessionState` object currently gets destroyed first, resulting in a dangling reference. Reordering the members of `HostTargetSession` results in the correct destruction order. bypass-github-export-checks Reviewed By: robhogan Differential Revision: D54305545 fbshipit-source-id: e91a6f3de5eed327b811524548d01565e26234fa --- .../ReactCommon/jsinspector-modern/HostTarget.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactCommon/jsinspector-modern/HostTarget.cpp b/packages/react-native/ReactCommon/jsinspector-modern/HostTarget.cpp index f5e95824412..4817e4d5757 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/HostTarget.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/HostTarget.cpp @@ -95,8 +95,10 @@ class HostTargetSession { // Owned by this instance, but shared (weakly) with the frontend channel std::shared_ptr remote_; FrontendChannel frontendChannel_; - HostAgent hostAgent_; SessionState state_; + + // NOTE: hostAgent_ has a raw reference to state_ so must be destroyed first. + HostAgent hostAgent_; }; std::shared_ptr HostTarget::create(