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
This commit is contained in:
Moti Zilberman
2024-02-28 11:33:54 -08:00
committed by Facebook GitHub Bot
parent 7cfd686214
commit 659712b475
@@ -95,8 +95,10 @@ class HostTargetSession {
// Owned by this instance, but shared (weakly) with the frontend channel
std::shared_ptr<RAIIRemoteConnection> 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> HostTarget::create(