From c0ebb02aab2734f422511aa0d347799b18b48894 Mon Sep 17 00:00:00 2001 From: lbl <1791778603@qq.com> Date: Mon, 16 Dec 2024 18:49:47 +0800 Subject: [PATCH 1/2] call WintunReleaseReceivePacket --- src/session.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/session.rs b/src/session.rs index f17c0b7..640ac34 100644 --- a/src/session.rs +++ b/src/session.rs @@ -173,10 +173,16 @@ impl Session { } let size = size as usize; if size > buf.len() { + unsafe { + wintun.WintunReleaseReceivePacket(self.inner.0, ptr); + } use std::io::{Error, ErrorKind::InvalidInput}; return Err(Error::new(InvalidInput, "destination buffer too small")); } unsafe { ptr::copy_nonoverlapping(ptr, buf.as_mut_ptr(), size) }; + unsafe { + wintun.WintunReleaseReceivePacket(self.inner.0, ptr); + } Ok(size) } From 8c945af8b8232b9df429d95957d7a0fd8afaef33 Mon Sep 17 00:00:00 2001 From: ssrlive <30760636+ssrlive@users.noreply.github.com> Date: Mon, 16 Dec 2024 20:19:19 +0800 Subject: [PATCH 2/2] minor changes --- src/session.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/session.rs b/src/session.rs index 640ac34..6fa36dc 100644 --- a/src/session.rs +++ b/src/session.rs @@ -173,16 +173,12 @@ impl Session { } let size = size as usize; if size > buf.len() { - unsafe { - wintun.WintunReleaseReceivePacket(self.inner.0, ptr); - } + unsafe { wintun.WintunReleaseReceivePacket(self.inner.0, ptr) }; use std::io::{Error, ErrorKind::InvalidInput}; return Err(Error::new(InvalidInput, "destination buffer too small")); } unsafe { ptr::copy_nonoverlapping(ptr, buf.as_mut_ptr(), size) }; - unsafe { - wintun.WintunReleaseReceivePacket(self.inner.0, ptr); - } + unsafe { wintun.WintunReleaseReceivePacket(self.inner.0, ptr) }; Ok(size) }