Skip to content

Commit

Permalink
Merge pull request #943 from mkroening/net-buf-leak
Browse files Browse the repository at this point in the history
fix(net): deallocate network buffers
  • Loading branch information
mkroening authored Oct 7, 2023
2 parents c31358a + d7b50ce commit 1a926d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/executor/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ impl<'a> NetworkInterface<'a> {
) -> (&mut T, &mut smoltcp::iface::Context) {
(self.sockets.get_mut(handle), self.iface.context())
}

pub(crate) fn destroy_socket(&mut self, handle: Handle) {
// This deallocates the socket's buffers
self.sockets.remove(handle);
}
}

#[inline]
Expand Down
4 changes: 4 additions & 0 deletions src/fd/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ impl<T> Socket<T> {
result
}

// TODO: Remove allow once fixed:
// https://github.com/rust-lang/rust-clippy/issues/11380
#[allow(clippy::needless_pass_by_ref_mut)]
async fn async_read(&self, buffer: &mut [u8]) -> Result<isize, i32> {
future::poll_fn(|cx| {
self.with(|socket| match socket.state() {
Expand Down Expand Up @@ -422,6 +425,7 @@ impl<T> Clone for Socket<T> {
impl<T> Drop for Socket<T> {
fn drop(&mut self) {
let _ = block_on(self.async_close(), None);
NIC.lock().as_nic_mut().unwrap().destroy_socket(self.handle);
}
}

Expand Down

0 comments on commit 1a926d7

Please sign in to comment.