From cfb6bf4c6b63a965b5fa862e4693d093a66544eb Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Fri, 17 Nov 2023 09:28:34 +0800 Subject: [PATCH] fix(bt/bluedroid): Avoided crash of LoadProhibited during HFP AG deinitialization Move the release of the control blocks from the start of deinitialization to the profile disabled event. --- .../bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c index 9f781a03f8..c40d364cd0 100644 --- a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c +++ b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c @@ -354,13 +354,16 @@ void btc_hf_deinit(void) { BTC_TRACE_EVENT("%s", __FUNCTION__); btc_dm_disable_service(BTA_HFP_SERVICE_ID); + hf_local_param[0].btc_hf_cb.initialized = false; +} + +static void btc_hf_cb_release(void) +{ #if HFP_DYNAMIC_MEMORY == TRUE if (hf_local_param) { osi_free(hf_local_param); hf_local_param = NULL; } -#else - hf_local_param[0].btc_hf_cb.initialized = false; #endif } @@ -1260,9 +1263,12 @@ void btc_hf_cb_handler(btc_msg_t *msg) switch (event) { case BTA_AG_ENABLE_EVT: - case BTA_AG_DISABLE_EVT: break; - + case BTA_AG_DISABLE_EVT: + { + btc_hf_cb_release(); + break; + } case BTA_AG_REGISTER_EVT: { idx = p_data->hdr.handle - 1;