Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_memory_leak_in_sco_v5.4' into 'release/v5.4'
Browse files Browse the repository at this point in the history
fix(bt/bluedroid): Fix memory leak in sco when bluedroid disable (v5.4)

See merge request espressif/esp-idf!34564
  • Loading branch information
Jiang Jiang Jian committed Nov 4, 2024
2 parents b21b729 + 6fe128a commit 0e6c74e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .codespellrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[codespell]
skip = build,*.yuv,components/fatfs/src/*,alice.txt,*.rgb,components/wpa_supplicant/*,components/esp_wifi/*,*.pem
ignore-words-list = ser,dout,rsource,fram,inout,shs,ans,aci,unstall,unstalling,hart,wheight,wel,ot,fane,assertIn,registr,oen
ignore-words-list = ser,dout,rsource,fram,inout,shs,ans,aci,unstall,unstalling,hart,wheight,wel,ot,fane,assertIn,registr,oen,parms
write-changes = true
3 changes: 3 additions & 0 deletions components/bt/host/bluedroid/stack/btm/btm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ void btm_free(void)
fixed_queue_free(btm_cb.sec_pending_q, osi_free_func);
btm_acl_free();
btm_sec_dev_free();
#if BTM_SCO_INCLUDED == TRUE
btm_sco_free();
#endif
#if BTM_DYNAMIC_MEMORY
FREE_AND_RESET(btm_cb_ptr);
#endif
Expand Down
20 changes: 18 additions & 2 deletions components/bt/host/bluedroid/stack/btm/btm_sco.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ void btm_sco_init (void)
btm_cb.sco_cb.desired_sco_mode = BTM_DEFAULT_SCO_MODE;
}

/*******************************************************************************
**
** Function btm_sco_free
**
** Description Free sco specific fixed_queue from btm control block
**
*******************************************************************************/
void btm_sco_free(void)
{
#if (BTM_SCO_HCI_INCLUDED == TRUE)
for (int i = 0; i < BTM_MAX_SCO_LINKS; i++) {
fixed_queue_free(btm_cb.sco_cb.sco_db[i].xmit_data_q, osi_free_func);
}
#endif
}

/*******************************************************************************
**
** Function btm_esco_conn_rsp
Expand Down Expand Up @@ -233,7 +249,7 @@ void btm_sco_process_num_bufs (UINT16 num_lm_sco_bufs)
** pointer is used, PCM parameter maintained in
** the control block will be used; otherwise update
** control block value.
** err_data_rpt: Lisbon feature to enable the erronous data report
** err_data_rpt: Lisbon feature to enable the erroneous data report
** or not.
**
** Returns BTM_SUCCESS if the successful.
Expand Down Expand Up @@ -947,7 +963,7 @@ void btm_sco_conn_req (BD_ADDR bda, DEV_CLASS dev_class, UINT8 link_type)
for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++) {
/*
* If the sco state is in the SCO_ST_CONNECTING state, we still need
* to return accept sco to avoid race conditon for sco creation
* to return accept sco to avoid race condition for sco creation
*/
int rem_bd_matches = p->rem_bd_known &&
!memcmp (p->esco.data.bd_addr, bda, BD_ADDR_LEN);
Expand Down
1 change: 1 addition & 0 deletions components/bt/host/bluedroid/stack/btm/include/btm_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ void btm_ble_periodic_adv_sync_trans_complete(UINT16 op_code, UINT8 hci_status,
********************************************
*/
void btm_sco_init (void);
void btm_sco_free(void);
void btm_sco_connected (UINT8 hci_status, BD_ADDR bda, UINT16 hci_handle,
tBTM_ESCO_DATA *p_esco_data);
void btm_esco_proc_conn_chg (UINT8 status, UINT16 handle, UINT8 tx_interval,
Expand Down

0 comments on commit 0e6c74e

Please sign in to comment.