Skip to content

Commit 1e22988

Browse files
committed
Merge branch 'bugfix/bluedroid_dynamic_allocation_issues' into 'master'
Bluedroid: Fix gatt clcb allocation error See merge request espressif/esp-idf!9679
2 parents 5593eae + a7d8d2c commit 1e22988

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

components/bt/host/bluedroid/stack/btm/btm_dev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ BOOLEAN BTM_SecDeleteDevice (BD_ADDR bd_addr, tBT_TRANSPORT transport)
186186
return FALSE;
187187
}
188188
if ((p_dev_rec = btm_find_dev(bd_addr)) != NULL) {
189-
btm_sec_free_dev(p_dev_rec, transport);
190-
191189
/* Tell controller to get rid of the link key, if it has one stored */
192190
BTM_DeleteStoredLinkKey (p_dev_rec->bd_addr, NULL);
191+
192+
btm_sec_free_dev(p_dev_rec, transport);
193193
}
194194

195195
return TRUE;

components/bt/host/bluedroid/stack/gatt/gatt_utils.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -784,19 +784,22 @@ BOOLEAN gatt_find_the_connected_bda(UINT8 start_idx, BD_ADDR bda, UINT8 *p_found
784784
GATT_TRACE_DEBUG("gatt_find_the_connected_bda start_idx=%d", start_idx);
785785
tGATT_TCB *p_tcb = NULL;
786786
list_node_t *p_node = NULL;
787-
for(p_node = list_begin(gatt_cb.p_tcb_list); p_node; p_node = list_next(p_node)) {
788-
p_tcb = list_node(p_node);
789-
if (p_tcb->in_use && p_tcb->ch_state == GATT_CH_OPEN) {
790-
memcpy( bda, p_tcb->peer_bda, BD_ADDR_LEN);
791-
*p_found_idx = p_tcb->tcb_idx;
792-
*p_transport = p_tcb->transport;
793-
found = TRUE;
794-
GATT_TRACE_DEBUG("gatt_find_the_connected_bda bda :%02x-%02x-%02x-%02x-%02x-%02x",
795-
bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
796-
break;
787+
p_tcb = gatt_get_tcb_by_idx(start_idx);
788+
if (p_tcb) {
789+
for(p_node = list_get_node(gatt_cb.p_tcb_list, p_tcb); p_node; p_node = list_next(p_node)) {
790+
p_tcb = list_node(p_node);
791+
if (p_tcb->in_use && p_tcb->ch_state == GATT_CH_OPEN) {
792+
memcpy( bda, p_tcb->peer_bda, BD_ADDR_LEN);
793+
*p_found_idx = p_tcb->tcb_idx;
794+
*p_transport = p_tcb->transport;
795+
found = TRUE;
796+
GATT_TRACE_DEBUG("gatt_find_the_connected_bda bda :%02x-%02x-%02x-%02x-%02x-%02x",
797+
bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
798+
break;
799+
}
797800
}
801+
GATT_TRACE_DEBUG("gatt_find_the_connected_bda found=%d found_idx=%d", found, p_tcb->tcb_idx);
798802
}
799-
GATT_TRACE_DEBUG("gatt_find_the_connected_bda found=%d found_idx=%d", found, p_tcb->tcb_idx);
800803
return found;
801804
}
802805

@@ -939,7 +942,9 @@ tGATT_TCB *gatt_get_tcb_by_idx(UINT8 tcb_idx)
939942
p_tcb = list_node(p_node);
940943
if ( (tcb_idx < GATT_MAX_PHY_CHANNEL) && p_tcb->in_use && p_tcb->tcb_idx == tcb_idx ) {
941944
break;
942-
}
945+
} else {
946+
p_tcb = NULL;
947+
}
943948
}
944949

945950
return p_tcb;
@@ -1754,6 +1759,7 @@ tGATT_CLCB *gatt_clcb_alloc (UINT16 conn_id)
17541759
if (list_length(gatt_cb.p_clcb_list) < GATT_CL_MAX_LCB) {
17551760
p_clcb = (tGATT_CLCB *)osi_malloc(sizeof(tGATT_CLCB));
17561761
if (p_clcb) {
1762+
list_append(gatt_cb.p_clcb_list, p_clcb);
17571763
memset(p_clcb, 0, sizeof(tGATT_CLCB));
17581764
p_clcb->in_use = TRUE;
17591765
p_clcb->conn_id = conn_id;
@@ -1781,6 +1787,7 @@ void gatt_clcb_dealloc (tGATT_CLCB *p_clcb)
17811787
btu_free_timer(&p_clcb->rsp_timer_ent);
17821788
memset(p_clcb, 0, sizeof(tGATT_CLCB));
17831789
list_remove(gatt_cb.p_clcb_list, p_clcb);
1790+
p_clcb = NULL;
17841791
}
17851792
}
17861793

@@ -2325,17 +2332,17 @@ void gatt_cleanup_upon_disc(BD_ADDR bda, UINT16 reason, tBT_TRANSPORT transport)
23252332
GATT_TRACE_DEBUG ("found p_tcb ");
23262333
gatt_set_ch_state(p_tcb, GATT_CH_CLOSE);
23272334
list_node_t *p_node = NULL;
2328-
for(p_node = list_begin(gatt_cb.p_clcb_list); p_node; p_node = list_next(p_node)) {
2335+
list_node_t *p_node_next = NULL;
2336+
for(p_node = list_begin(gatt_cb.p_clcb_list); p_node; p_node = p_node_next) {
23292337
p_clcb = list_node(p_node);
2338+
p_node_next = list_next(p_node);
23302339
if (p_clcb->in_use && p_clcb->p_tcb == p_tcb) {
23312340
btu_stop_timer(&p_clcb->rsp_timer_ent);
23322341
GATT_TRACE_DEBUG ("found p_clcb conn_id=%d clcb_idx=%d", p_clcb->conn_id, p_clcb->clcb_idx);
23332342
if (p_clcb->operation != GATTC_OPTYPE_NONE) {
23342343
gatt_end_operation(p_clcb, GATT_ERROR, NULL);
23352344
}
2336-
23372345
gatt_clcb_dealloc(p_clcb);
2338-
23392346
}
23402347
}
23412348

0 commit comments

Comments
 (0)