diff --git a/src/executor/network.rs b/src/executor/network.rs index 78122626e5..21ca5ede19 100644 --- a/src/executor/network.rs +++ b/src/executor/network.rs @@ -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] diff --git a/src/fd/socket/tcp.rs b/src/fd/socket/tcp.rs index b6fabb1491..8d464f1dd7 100644 --- a/src/fd/socket/tcp.rs +++ b/src/fd/socket/tcp.rs @@ -66,6 +66,9 @@ impl Socket { 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 { future::poll_fn(|cx| { self.with(|socket| match socket.state() { @@ -422,6 +425,7 @@ impl Clone for Socket { impl Drop for Socket { fn drop(&mut self) { let _ = block_on(self.async_close(), None); + NIC.lock().as_nic_mut().unwrap().destroy_socket(self.handle); } }