avoid l2cap-channel list corruption (detected by alan-thx)

This commit is contained in:
matthias.ringwald 2011-11-09 16:36:59 +00:00
parent c7cccff7fb
commit 756102d34c

View File

@ -344,7 +344,9 @@ void l2cap_run(void){
uint8_t config_options[4];
linked_item_t *it;
for (it = (linked_item_t *) l2cap_channels; it ; it = it->next){
linked_item_t *next;
for (it = (linked_item_t *) l2cap_channels; it ; it = next){
next = it->next; // cache next item as current item might get freed
if (!hci_can_send_packet_now(HCI_COMMAND_DATA_PACKET)) break;
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)) break;
@ -366,7 +368,7 @@ void l2cap_run(void){
case L2CAP_STATE_WILL_SEND_CONNECTION_RESPONSE_DECLINE:
l2cap_send_signaling_packet(channel->handle, CONNECTION_RESPONSE, channel->remote_sig_id, 0, 0, channel->reason, 0);
// discard channel - l2cap_finialize_channel_close without sending l2cap close event
linked_list_remove(&l2cap_channels, (linked_item_t *) channel);
linked_list_remove(&l2cap_channels, (linked_item_t *) channel); // -- remove from list
btstack_memory_l2cap_channel_free(channel);
break;
@ -407,7 +409,7 @@ void l2cap_run(void){
case L2CAP_STATE_WILL_SEND_DISCONNECT_RESPONSE:
l2cap_send_signaling_packet( channel->handle, DISCONNECTION_RESPONSE, channel->remote_sig_id, channel->local_cid, channel->remote_cid);
l2cap_finialize_channel_close(channel);
l2cap_finialize_channel_close(channel); // -- remove from list
break;
case L2CAP_STATE_WILL_SEND_DISCONNECT_REQUEST: