[bt][hci] Fix use-after-free in CommandChannel
BT-904 #done
Test: bt-host-unittests with
fx set ... --variant={asan/bt-host,asan/bt-host-unittests}
Change-Id: Ieb127b98394e52436d173bda536c9fabe9cfc357
diff --git a/src/connectivity/bluetooth/core/bt-host/hci/command_channel.cc b/src/connectivity/bluetooth/core/bt-host/hci/command_channel.cc
index 9b4845a..37cd9cf 100644
--- a/src/connectivity/bluetooth/core/bt-host/hci/command_channel.cc
+++ b/src/connectivity/bluetooth/core/bt-host/hci/command_channel.cc
@@ -570,8 +570,8 @@
bt_log(DEBUG, "hci",
"removing completed async handler (id %zu, event code: %#.2x)",
event_id, event_code);
- RemoveEventHandlerInternal(event_id);
pending_transactions_.erase(handler.pending_opcode);
+ RemoveEventHandlerInternal(event_id); // |handler| is now dangling.
}
pending_callbacks.emplace_back(std::move(callback), dispatcher);