Skip to content
This repository was archived by the owner on Oct 24, 2022. It is now read-only.

Commit b109e4d

Browse files
committed
Remove extranous calls to libc::close.
We were explicitly calling libc::close() on fds we were replacing; but since they were stored as EventFds, which close themselves on drop, this is unnecessary. Manually closing them is useless at best; at worse, if there's a race condition and another thread opens an fd between the manual close and the normal close on drop, we could have closed someone else's fd.
1 parent 5b8655c commit b109e4d

File tree

1 file changed

+0
-12
lines changed

1 file changed

+0
-12
lines changed

src/lib.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -769,10 +769,6 @@ impl<S: VhostUserBackend> VhostUserSlaveReqHandlerMut for VhostUserHandler<S> {
769769
return Err(VhostUserError::InvalidParam);
770770
}
771771

772-
if let Some(kick) = self.vrings[index as usize].write().unwrap().kick.take() {
773-
// Close file descriptor set by previous operations.
774-
let _ = unsafe { libc::close(kick.as_raw_fd()) };
775-
}
776772
// SAFETY: EventFd requires that it has sole ownership of its fd. So
777773
// does File, so this is safe.
778774
// Ideally, we'd have a generic way to refer to a uniquely-owned fd,
@@ -811,10 +807,6 @@ impl<S: VhostUserBackend> VhostUserSlaveReqHandlerMut for VhostUserHandler<S> {
811807
return Err(VhostUserError::InvalidParam);
812808
}
813809

814-
if let Some(call) = self.vrings[index as usize].write().unwrap().call.take() {
815-
// Close file descriptor set by previous operations.
816-
let _ = unsafe { libc::close(call.as_raw_fd()) };
817-
}
818810
// SAFETY: see comment in set_vring_kick()
819811
self.vrings[index as usize].write().unwrap().call =
820812
file.map(|f| unsafe { EventFd::from_raw_fd(f.into_raw_fd()) });
@@ -827,10 +819,6 @@ impl<S: VhostUserBackend> VhostUserSlaveReqHandlerMut for VhostUserHandler<S> {
827819
return Err(VhostUserError::InvalidParam);
828820
}
829821

830-
if let Some(err) = self.vrings[index as usize].write().unwrap().err.take() {
831-
// Close file descriptor set by previous operations.
832-
let _ = unsafe { libc::close(err.as_raw_fd()) };
833-
}
834822
// SAFETY: see comment in set_vring_kick()
835823
self.vrings[index as usize].write().unwrap().err =
836824
file.map(|f| unsafe { EventFd::from_raw_fd(f.into_raw_fd()) });

0 commit comments

Comments
 (0)