From 4f73e87a6f930ea446d4bf01cc273fd2b8ef3d97 Mon Sep 17 00:00:00 2001 From: Janusz Sobczak Date: Mon, 12 Jun 2023 16:26:44 -0700 Subject: [PATCH] Improve device lost handling Handle the error case when the platform calls device_lost_cb without calling device_discovered_cb first. PiperOrigin-RevId: 539791976 --- internal/platform/bluetooth_classic.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/platform/bluetooth_classic.cc b/internal/platform/bluetooth_classic.cc index beade20d..1ab855b0 100644 --- a/internal/platform/bluetooth_classic.cc +++ b/internal/platform/bluetooth_classic.cc @@ -73,6 +73,11 @@ bool BluetoothClassicMedium::StartDiscovery(DiscoveryCallback callback) { [this](api::BluetoothDevice& device) { MutexLock lock(&mutex_); auto item = devices_.extract(&device); + if (!item) { + NEARBY_LOGS(WARNING) + << "Removing unknown device: " << device.GetMacAddress(); + return; + } auto& context = *item.mapped(); NEARBY_LOG(INFO, "Removing device=%p, impl=%p", &context.device, &device);