Skip to content

Commit

Permalink
samples: Bluetooth: Broadcast Audio Source: Fix potential memory leak
Browse files Browse the repository at this point in the history
In error cases, where send_data() returns early, the allocated net_buf
is not free'd, causing a memory leak affecting the net_buf pool.
Fix this by freeing the allocated net_buf before returning early
from send_data().

Signed-off-by: Sean Farrelly <[email protected]>
  • Loading branch information
FARLY7 authored and henrikbrixandersen committed Feb 14, 2024
1 parent 6bb5076 commit 9e28e9e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions samples/bluetooth/broadcast_audio_source/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ static void send_data(struct broadcast_source_stream *source_stream)

if (source_stream->lc3_encoder == NULL) {
printk("LC3 encoder not setup, cannot encode data.\n");
net_buf_unref(buf);
return;
}

Expand All @@ -190,6 +191,7 @@ static void send_data(struct broadcast_source_stream *source_stream)
send_pcm_data, 1, octets_per_frame, lc3_encoded_buffer);
if (ret == -1) {
printk("LC3 encoder failed - wrong parameters?: %d", ret);
net_buf_unref(buf);
return;
}

Expand Down

0 comments on commit 9e28e9e

Please sign in to comment.