Skip to content

Commit 4643ceb

Browse files
fix(bt/bluedroid): fixed access NULL in HFP callback handler
1 parent c132475 commit 4643ceb

File tree

1 file changed

+33
-17
lines changed
  • components/bt/host/bluedroid/btc/profile/std/hf_ag

1 file changed

+33
-17
lines changed

components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,17 @@ bt_status_t btc_hf_init(void)
316316
{
317317
int idx = 0;
318318

319-
if (hf_local_param[idx].btc_hf_cb.initialized) {
320-
esp_hf_cb_param_t param = {
321-
.prof_stat.state = ESP_HF_INIT_ALREADY,
322-
};
323-
btc_hf_cb_to_app(ESP_HF_PROF_STATE_EVT, &param);
324-
return BT_STATUS_SUCCESS;
319+
#if HFP_DYNAMIC_MEMORY == TRUE
320+
if (hf_local_param)
321+
#endif
322+
{
323+
if (hf_local_param[idx].btc_hf_cb.initialized) {
324+
esp_hf_cb_param_t param = {
325+
.prof_stat.state = ESP_HF_INIT_ALREADY,
326+
};
327+
btc_hf_cb_to_app(ESP_HF_PROF_STATE_EVT, &param);
328+
return BT_STATUS_SUCCESS;
329+
}
325330
}
326331

327332
BTC_TRACE_DEBUG("%s - max_hf_clients=%d", __func__, btc_max_hf_clients);
@@ -364,12 +369,18 @@ void btc_hf_deinit(void)
364369
BTC_TRACE_EVENT("%s", __FUNCTION__);
365370

366371
int idx = 0;
367-
if (!hf_local_param[idx].btc_hf_cb.initialized) {
368-
esp_hf_cb_param_t param = {
369-
.prof_stat.state = ESP_HF_DEINIT_ALREADY,
370-
};
371-
btc_hf_cb_to_app(ESP_HF_PROF_STATE_EVT, &param);
372-
return;
372+
373+
#if HFP_DYNAMIC_MEMORY == TRUE
374+
if (hf_local_param)
375+
#endif
376+
{
377+
if (!hf_local_param[idx].btc_hf_cb.initialized) {
378+
esp_hf_cb_param_t param = {
379+
.prof_stat.state = ESP_HF_DEINIT_ALREADY,
380+
};
381+
btc_hf_cb_to_app(ESP_HF_PROF_STATE_EVT, &param);
382+
return;
383+
}
373384
}
374385

375386
btc_dm_disable_service(BTA_HFP_SERVICE_ID);
@@ -1285,12 +1296,17 @@ void btc_hf_cb_handler(btc_msg_t *msg)
12851296
case BTA_AG_DISABLE_EVT:
12861297
{
12871298
idx = 0;
1288-
btc_hf_cb_release();
1289-
if (hf_local_param[idx].btc_hf_cb.initialized) {
1290-
param.prof_stat.state = ESP_HF_DEINIT_SUCCESS;
1291-
btc_hf_cb_to_app(ESP_HF_PROF_STATE_EVT, &param);
1299+
#if HFP_DYNAMIC_MEMORY == TRUE
1300+
if (hf_local_param)
1301+
#endif
1302+
{
1303+
if (hf_local_param[idx].btc_hf_cb.initialized) {
1304+
hf_local_param[idx].btc_hf_cb.initialized = false;
1305+
btc_hf_cb_release();
1306+
param.prof_stat.state = ESP_HF_DEINIT_SUCCESS;
1307+
btc_hf_cb_to_app(ESP_HF_PROF_STATE_EVT, &param);
1308+
}
12921309
}
1293-
hf_local_param[idx].btc_hf_cb.initialized = false;
12941310
break;
12951311
}
12961312
case BTA_AG_REGISTER_EVT:

0 commit comments

Comments
 (0)