diff --git a/remoting/host/delegating_desktop_display_info_monitor.cc b/remoting/host/delegating_desktop_display_info_monitor.cc index 814b3b4ecb5c7..7aaa4d161623f 100644 --- a/remoting/host/delegating_desktop_display_info_monitor.cc +++ b/remoting/host/delegating_desktop_display_info_monitor.cc @@ -29,9 +29,14 @@ void DelegatingDesktopDisplayInfoMonitor::Start() { } started_ = true; + // The underlying monitor may outlive |this| (e.g. on the Linux Wayland + // XDG-portal path it is owned by a base::NoDestructor singleton while |this| + // is per-ClientSession). AddCallback() uses AddUnsafe() and provides no way + // to unsubscribe, so bind to a WeakPtr to avoid a use-after-free when the + // underlying monitor notifies after |this| is destroyed. underlying_->AddCallback(base::BindRepeating( &DelegatingDesktopDisplayInfoMonitor::OnUnderlyingDisplayInfoChanged, - base::Unretained(this))); + weak_ptr_factory_.GetWeakPtr())); if (underlying_->IsStarted()) { if (underlying_->GetLatestDisplayInfo()) { // Notify that the display info is available on the next task frame to