summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--system/main/shim/stack.cc16
1 files changed, 13 insertions, 3 deletions
diff --git a/system/main/shim/stack.cc b/system/main/shim/stack.cc
index 14447d75b3..bb8994aee0 100644
--- a/system/main/shim/stack.cc
+++ b/system/main/shim/stack.cc
@@ -169,8 +169,11 @@ void Stack::Stop() {
log::assert_that(is_running_, "Gd stack not running");
is_running_ = false;
- stack_handler_->Clear();
-
+ if (!com::android::bluetooth::flags::same_handler_for_all_modules()) {
+ // Clear the handler only if the flag is not defined, otherwise it will be cleared by the
+ // registry
+ stack_handler_->Clear();
+ }
WakelockManager::Get().Acquire();
std::promise<void> promise;
@@ -192,7 +195,14 @@ void Stack::Stop() {
delete management_handler_;
delete management_thread_;
- delete stack_handler_;
+ if (!com::android::bluetooth::flags::same_handler_for_all_modules()) {
+ // delete the handler only if the flag is not defined, otherwise it will be deleted by the
+ // registry
+ delete stack_handler_;
+ }
+
+ // stack_handler_ is already deleted by the registry in handle_shut_down, just set it to nullptr
+ // to avoid any potential use-after-free
stack_handler_ = nullptr;
stack_thread_->Stop();