From b0171a54ebf5185259fbb741d771c573d0934ad7 Mon Sep 17 00:00:00 2001 From: emaxx Date: Fri, 30 Oct 2015 06:18:49 -0700 Subject: Fix occasional crash in ~VPNListView during shell destruction. The crash is caused by the fact that during the ash::Shell destruction the SystemTrayDelegate object is destroyed before the child windows are closed - but apparently the VPNListView destructor accesses SystemTrayDelegate's members without any checks. BUG=542146 TEST=manual testing Review URL: https://codereview.chromium.org/1410033002 Cr-Commit-Position: refs/heads/master@{#357088} --- ash/system/chromeos/network/vpn_delegate.h | 2 +- ash/system/chromeos/network/vpn_list_view.cc | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'ash') diff --git a/ash/system/chromeos/network/vpn_delegate.h b/ash/system/chromeos/network/vpn_delegate.h index aaf76a3..fd6fe72 100644 --- a/ash/system/chromeos/network/vpn_delegate.h +++ b/ash/system/chromeos/network/vpn_delegate.h @@ -91,7 +91,7 @@ class ASH_EXPORT VPNDelegate { void NotifyObservers(); private: - base::ObserverList observer_list_; + base::ObserverList observer_list_; DISALLOW_COPY_AND_ASSIGN(VPNDelegate); }; diff --git a/ash/system/chromeos/network/vpn_list_view.cc b/ash/system/chromeos/network/vpn_list_view.cc index d3f3061..a80853b 100644 --- a/ash/system/chromeos/network/vpn_list_view.cc +++ b/ash/system/chromeos/network/vpn_list_view.cc @@ -239,10 +239,14 @@ VPNListView::VPNListView(ui::NetworkListDelegate* delegate) } VPNListView::~VPNListView() { - Shell::GetInstance() - ->system_tray_delegate() - ->GetVPNDelegate() - ->RemoveObserver(this); + // We need the check as on shell destruction, the delegate is destroyed first. + SystemTrayDelegate* const system_tray_delegate = + Shell::GetInstance()->system_tray_delegate(); + if (system_tray_delegate) { + VPNDelegate* const vpn_delegate = system_tray_delegate->GetVPNDelegate(); + if (vpn_delegate) + vpn_delegate->RemoveObserver(this); + } } void VPNListView::Update() { -- cgit v1.1