From 4e312064030622dcb6533facb94787ddfc1c7b28 Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Tue, 9 Aug 2022 08:41:22 -0700 Subject: [PATCH] test_infra: Avoid file descriptor leak with epoll Signed-off-by: Bo Chen --- test_infra/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test_infra/src/lib.rs b/test_infra/src/lib.rs index e1c95faef..da613907a 100644 --- a/test_infra/src/lib.rs +++ b/test_infra/src/lib.rs @@ -14,7 +14,7 @@ use std::io::{Read, Write}; use std::net::TcpListener; use std::net::TcpStream; use std::os::unix::fs::PermissionsExt; -use std::os::unix::io::AsRawFd; +use std::os::unix::io::{AsRawFd, FromRawFd}; use std::path::Path; use std::process::{Child, Command, ExitStatus, Output, Stdio}; use std::str::FromStr; @@ -82,6 +82,8 @@ impl GuestNetworkConfig { // Reply on epoll w/ timeout to wait for guest connections faithfully let epoll_fd = epoll::create(true).expect("Cannot create epoll fd"); + // Use 'File' to enforce closing on 'epoll_fd' + let _epoll_file = unsafe { fs::File::from_raw_fd(epoll_fd) }; epoll::ctl( epoll_fd, epoll::ControlOptions::EPOLL_CTL_ADD,