From b4cc2c96aea71a95daf0f7e4cece045bfce9a6ad Mon Sep 17 00:00:00 2001 From: John Nunley Date: Sun, 19 May 2024 14:21:54 -0700 Subject: [PATCH] tests: Avoid free-ing a random FD in OwnedFd drop In the insert_bad_source test, we drop the FD "420", which doesn't exist. Previously the error was ignored, but in the latest nightly it now aborts the program. This commit fixes this by leaking the bad "OwnedFd" instead of leaving it to be dropped. Signed-off-by: John Nunley --- src/loop_logic.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/loop_logic.rs b/src/loop_logic.rs index 1b246814..a4e89085 100644 --- a/src/loop_logic.rs +++ b/src/loop_logic.rs @@ -1153,10 +1153,21 @@ mod tests { #[cfg(unix)] #[test] fn insert_bad_source() { - use std::os::unix::io::FromRawFd; + use std::mem::ManuallyDrop; + use std::os::unix::io::{AsFd, FromRawFd, OwnedFd}; + + struct LeakedFd(ManuallyDrop); + + impl AsFd for LeakedFd { + fn as_fd(&self) -> std::os::unix::prelude::BorrowedFd<'_> { + self.0.as_fd() + } + } let event_loop = EventLoop::<()>::try_new().unwrap(); - let fd = unsafe { std::os::unix::io::OwnedFd::from_raw_fd(420) }; + let fd = LeakedFd(ManuallyDrop::new(unsafe { + std::os::unix::io::OwnedFd::from_raw_fd(420) + })); let ret = event_loop.handle().insert_source( crate::sources::generic::Generic::new(fd, Interest::READ, Mode::Level), |_, _, _| Ok(PostAction::Continue),