Bluetooth: Protect callbacks during shutdown
- Hold the mutex during callbacks
- Disable power mode before deleting hci_
Bug: 36084266
Test: Switch users repeatedly (toggles Bluetooth)
Change-Id: I7e4d405e9028c3363c112a8b09c03b8aea652b7a
diff --git a/bluetooth/1.0/default/async_fd_watcher.cc b/bluetooth/1.0/default/async_fd_watcher.cc
index 2f23a69..05ac537 100644
--- a/bluetooth/1.0/default/async_fd_watcher.cc
+++ b/bluetooth/1.0/default/async_fd_watcher.cc
@@ -159,19 +159,13 @@
}
// Invoke the data ready callbacks if appropriate.
- std::vector<decltype(watched_fds_)::value_type> saved_callbacks;
{
+ // Hold the mutex to make sure that the callbacks are still valid.
std::unique_lock<std::mutex> guard(internal_mutex_);
for (auto& it : watched_fds_) {
if (FD_ISSET(it.first, &read_fds)) {
- saved_callbacks.push_back(it);
- }
- }
- }
-
- for (auto& it : saved_callbacks) {
- if (it.second) {
it.second(it.first);
+ }
}
}
}