From 18c8a22486819ab88e552b39eee8add0894afed9 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 12 Dec 2021 20:15:47 +0100 Subject: lib: close console fd on drop --- src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 4ff9bba..6a932d8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -998,6 +998,20 @@ impl Console } } +impl Drop for Console +{ + fn drop(&mut self) + { + if unsafe { libc::close(self.0) } == -1 { + eprintln!( + "Console: error closing fd {}: {}", + self.0, + Error::last_os_error() + ); + } + } +} + impl AsRawFd for Console { fn as_raw_fd(&self) -> RawFd { self.0 } -- cgit v1.2.3