Skip to content

Commit

Permalink
Only close TimerFd file descriptor if not panicking
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Dumoulin committed Feb 8, 2021
1 parent 4c9ee5c commit cd5de70
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Added limited Fuchsia support (#[1285](https://github.com/nix-rust/nix/pull/1285))
- Added `getpeereid` (#[1342](https://github.com/nix-rust/nix/pull/1342))
### Fixed
- TimerFd now closes the underlying fd on drop.
- `TimerFd` now closes the underlying fd on drop.
([#1381](https://github.com/nix-rust/nix/pull/1381))
### Changed

Expand All @@ -27,6 +27,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).

- Removed `SockLevel`, which hasn't been used for a few years
(#[1362](https://github.com/nix-rust/nix/pull/1362))
- Removed both `Copy` and `Clone` from `TimerFd`.
([#1381](https://github.com/nix-rust/nix/pull/1381))

## [0.19.1] - 28 November 2020
### Fixed
Expand Down
12 changes: 7 additions & 5 deletions src/sys/timerfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,13 @@ impl TimerFd {

impl Drop for TimerFd {
fn drop(&mut self) {
let result = Errno::result(unsafe {
libc::close(self.fd)
});
if let Err(Error::Sys(Errno::EBADF)) = result {
panic!("close of TimerFd encountered EBADF");
if !std::thread::panicking() {
let result = Errno::result(unsafe {
libc::close(self.fd)
});
if let Err(Error::Sys(Errno::EBADF)) = result {
panic!("close of TimerFd encountered EBADF");
}
}
}
}

0 comments on commit cd5de70

Please sign in to comment.