From 5b9131cc60e15745bf8f266bdc4156c1a5087c12 Mon Sep 17 00:00:00 2001 From: yulong Date: Tue, 28 Nov 2017 15:43:33 +0800 Subject: [PATCH 1/2] compoent/bt: Fix the bug when do the BLE pressure test will lead to memory leak will appear WDT. --- components/bt/bluedroid/bta/gatt/bta_gattc_utils.c | 6 ++++-- components/bt/bluedroid/stack/gatt/gatt_utils.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c b/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c index b5409b40b3..676ed851ac 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c @@ -232,8 +232,9 @@ tBTA_GATTC_CLCB *bta_gattc_clcb_alloc(tBTA_GATTC_IF client_if, BD_ADDR remote_bd bdcpy(p_clcb->bda, remote_bda); p_clcb->p_rcb = bta_gattc_cl_get_regcb(client_if); - p_clcb->p_cmd_list = list_new(osi_free_func); - + if (p_clcb->p_cmd_list == NULL) { + p_clcb->p_cmd_list = list_new(osi_free_func); + } if ((p_clcb->p_srcb = bta_gattc_find_srcb(remote_bda)) == NULL) { p_clcb->p_srcb = bta_gattc_srcb_alloc(remote_bda); } @@ -310,6 +311,7 @@ void bta_gattc_clcb_dealloc(tBTA_GATTC_CLCB *p_clcb) p_clcb->p_q_cmd = NULL; // don't forget to clear the command queue before dealloc the clcb. list_clear(p_clcb->p_cmd_list); + osi_free((void *)p_clcb->p_cmd_list); //osi_free_and_reset((void **)&p_clcb->p_q_cmd); memset(p_clcb, 0, sizeof(tBTA_GATTC_CLCB)); } else { diff --git a/components/bt/bluedroid/stack/gatt/gatt_utils.c b/components/bt/bluedroid/stack/gatt/gatt_utils.c index 9d2ae16f7c..5b0db44e9e 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_utils.c +++ b/components/bt/bluedroid/stack/gatt/gatt_utils.c @@ -861,7 +861,7 @@ tGATTS_SRV_CHG *gatt_is_bda_in_the_srv_chg_clt_list (BD_ADDR bda) list_t *list = fixed_queue_get_list(gatt_cb.srv_chg_clt_q); for (const list_node_t *node = list_begin(list); node != list_end(list); node = list_next(node)) { - tGATTS_SRV_CHG *p_buf = (tGATTS_SRV_CHG *)list_node(node); + p_buf = (tGATTS_SRV_CHG *)list_node(node); if (!memcmp( bda, p_buf->bda, BD_ADDR_LEN)) { GATT_TRACE_DEBUG("bda is in the srv chg clt list"); break; From 7353307ca5219f9906a7d00951b4e7740d0de331 Mon Sep 17 00:00:00 2001 From: yulong Date: Wed, 29 Nov 2017 10:50:03 +0800 Subject: [PATCH 2/2] component/bt: reset the p_cmd_list pointer after release the mem. --- components/bt/bluedroid/bta/gatt/bta_gattc_utils.c | 1 + 1 file changed, 1 insertion(+) diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c b/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c index 676ed851ac..70655fd944 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c @@ -312,6 +312,7 @@ void bta_gattc_clcb_dealloc(tBTA_GATTC_CLCB *p_clcb) // don't forget to clear the command queue before dealloc the clcb. list_clear(p_clcb->p_cmd_list); osi_free((void *)p_clcb->p_cmd_list); + p_clcb->p_cmd_list = NULL; //osi_free_and_reset((void **)&p_clcb->p_q_cmd); memset(p_clcb, 0, sizeof(tBTA_GATTC_CLCB)); } else {