diff options
| author | Joakim Hulthe <joakim@hulthe.net> | 2025-05-07 12:41:34 +0200 |
|---|---|---|
| committer | Joakim Hulthe <joakim.hulthe@mullvad.net> | 2025-05-14 18:00:30 +0200 |
| commit | 3c046f8ccda41a95f4495e7147c7c09842b7c5bd (patch) | |
| tree | 2d1332096298137aa0542731b92a12ba04ec00f4 | |
| parent | 507c5201239d8d95216aa6b2980d15b031960964 (diff) | |
| download | mullvadvpn-3c046f8ccda41a95f4495e7147c7c09842b7c5bd.tar.xz mullvadvpn-3c046f8ccda41a95f4495e7147c7c09842b7c5bd.zip | |
Use OnDrop from talpid-types in wggors
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | wireguard-go-rs/Cargo.toml | 2 | ||||
| -rw-r--r-- | wireguard-go-rs/src/lib.rs | 6 | ||||
| -rw-r--r-- | wireguard-go-rs/src/util.rs | 15 |
4 files changed, 5 insertions, 19 deletions
diff --git a/Cargo.lock b/Cargo.lock index 40b362601c..6d761edd51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6764,6 +6764,7 @@ dependencies = [ "anyhow", "log", "maybenot-ffi", + "talpid-types", "thiserror 2.0.9", "windows-sys 0.52.0", "zeroize", diff --git a/wireguard-go-rs/Cargo.toml b/wireguard-go-rs/Cargo.toml index 8a7404cffd..415365e772 100644 --- a/wireguard-go-rs/Cargo.toml +++ b/wireguard-go-rs/Cargo.toml @@ -12,6 +12,8 @@ thiserror.workspace = true log.workspace = true zeroize = "1.8.1" +talpid-types.path = "../talpid-types" + # On platforms where maybenot and wireguard-go can be built statically (Linux and macOS) we use # this hack to include it. The hack is that we depend on this crate here even if neither # wireguard-go-rs nor its upstream dependants use it. diff --git a/wireguard-go-rs/src/lib.rs b/wireguard-go-rs/src/lib.rs index 37756a7afb..6ac5c928f3 100644 --- a/wireguard-go-rs/src/lib.rs +++ b/wireguard-go-rs/src/lib.rs @@ -13,13 +13,11 @@ use core::mem::MaybeUninit; use core::slice; #[cfg(target_os = "windows")] use std::ffi::CString; -use util::OnDrop; +use talpid_types::drop_guard::on_drop; #[cfg(target_os = "windows")] use windows_sys::Win32::NetworkManagement::Ndis::NET_LUID_LH; use zeroize::Zeroize; -mod util; - #[cfg(unix)] pub type Fd = std::os::unix::io::RawFd; @@ -223,7 +221,7 @@ impl Tunnel { let config_len = config.to_bytes().len(); // execute cleanup code on Drop to make sure that it happens even if `f` panics - let on_drop = OnDrop::new(|| { + let on_drop = on_drop(|| { { // SAFETY: // we checked for null, and wgGetConfig promises that this is a valid cstr. diff --git a/wireguard-go-rs/src/util.rs b/wireguard-go-rs/src/util.rs deleted file mode 100644 index 4c2df2f9bb..0000000000 --- a/wireguard-go-rs/src/util.rs +++ /dev/null @@ -1,15 +0,0 @@ -pub struct OnDrop<F: FnOnce()>(Option<F>); - -impl<F: FnOnce()> OnDrop<F> { - pub fn new(f: F) -> Self { - OnDrop(Some(f)) - } -} - -impl<F: FnOnce()> Drop for OnDrop<F> { - fn drop(&mut self) { - if let Some(f) = self.0.take() { - f() - } - } -} |
