Skip to content

Commit

Permalink
Bluetooth: ATT: free current buffer when disconnected
Browse files Browse the repository at this point in the history
`att_send_process` doesn't pass the errors up the stack, so if a
disconnection happens during the allocation of a TX context, it will
leak buffers.

Fixes zephyrproject-rtos#43718

Signed-off-by: Jonathan Rico <[email protected]>
  • Loading branch information
jori-nordic committed Apr 29, 2022
1 parent 1b10f83 commit 2215bf0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion subsys/bluetooth/host/att.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,11 @@ static void att_send_process(struct bt_att *att)
}
}

if (err < 0) {
if (err == -ENOTCONN) {
/* If we are not connected anymore, free the buffer */
BT_ERR("Freeing buf %p id %d", buf, net_buf_id(buf));
net_buf_unref(buf);

This comment has been minimized.

Copy link
@jori-nordic

jori-nordic Apr 29, 2022

Author Owner

shouldn't need to do this, I should rather check that the conn_cleanup does its job properly.

} else if (err < 0) {
/* Push it back if it could not be send */
k_queue_prepend(&att->tx_queue._queue, buf);
}
Expand Down

0 comments on commit 2215bf0

Please sign in to comment.