Skip to content

Commit

Permalink
tests: Avoid free-ing a random FD in OwnedFd drop
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
notgull committed May 19, 2024
1 parent 640ef73 commit aaa4afd
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/loop_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OwnedFd>);

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),
Expand Down

0 comments on commit aaa4afd

Please sign in to comment.