0

[floss] Check DBusManager is valid before removing observer

Fixes a crash where DBusManager is no longer valid during
various Floss destructors.

BUG=b:378842041
TEST=device_unittests

Change-Id: Ic248a3769a4ea6f3afa4560828f8562fb928982d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6042577
Commit-Queue: Daniel Classon <dclasson@google.com>
Auto-Submit: Katherine Lai <laikatherine@chromium.org>
Reviewed-by: Daniel Classon <dclasson@google.com>
Cr-Commit-Position: refs/heads/main@{#1387017}
This commit is contained in:
Katherine Lai
2024-11-22 20:05:53 +00:00
committed by Chromium LUCI CQ
parent 1047d75f09
commit 4674e363fd
2 changed files with 7 additions and 3 deletions

@ -716,7 +716,9 @@ BluetoothDeviceFloss::BluetoothDeviceFloss(
}
BluetoothDeviceFloss::~BluetoothDeviceFloss() {
FlossDBusManager::Get()->GetGattManagerClient()->RemoveObserver(this);
if (floss::FlossDBusManager::IsInitialized()) {
FlossDBusManager::Get()->GetGattManagerClient()->RemoveObserver(this);
}
}
bool BluetoothDeviceFloss::IsBondedImpl() const {

@ -31,8 +31,10 @@ BluetoothGattServiceFloss::BluetoothGattServiceFloss(
}
BluetoothGattServiceFloss::~BluetoothGattServiceFloss() {
FlossDBusManager::Get()->GetGattManagerClient()->RemoveObserver(this);
FlossDBusManager::Get()->GetGattManagerClient()->RemoveServerObserver(this);
if (floss::FlossDBusManager::IsInitialized()) {
FlossDBusManager::Get()->GetGattManagerClient()->RemoveObserver(this);
FlossDBusManager::Get()->GetGattManagerClient()->RemoveServerObserver(this);
}
}
BluetoothAdapterFloss* BluetoothGattServiceFloss::GetAdapter() const {