Skip to content

Commit

Permalink
Free tx buffer on ipc send failure
Browse files Browse the repository at this point in the history
  • Loading branch information
lulf committed Dec 3, 2024
1 parent 4acc0f8 commit 6065bc6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions embassy-net-nrf91/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ impl StateInner {
if data.is_empty() {
msg.data = ptr::null_mut();
msg.data_len = 0;
self.send_message_raw(msg)
} else {
assert!(data.len() <= TX_BUF_SIZE);
let buf_idx = self.find_free_tx_buf().ok_or(NoFreeBufs)?;
Expand All @@ -517,10 +518,15 @@ impl StateInner {
self.tx_buf_used[buf_idx] = true;

fence(Ordering::SeqCst); // synchronize copy_nonoverlapping (non-volatile) with volatile writes below.
if let Err(e) = self.send_message_raw(msg) {
msg.data = ptr::null_mut();
msg.data_len = 0;
self.tx_buf_used[buf_idx] = false;
Err(e)
} else {
Ok(())
}
}

// TODO free data buf if send_message_raw fails.
self.send_message_raw(msg)
}

fn send_message_raw(&mut self, msg: &Message) -> Result<(), NoFreeBufs> {
Expand Down

0 comments on commit 6065bc6

Please sign in to comment.