From 41f345d319c3d63429b05e816a91ffd35732294a Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Sun, 8 Sep 2019 19:18:37 +0200 Subject: [PATCH] Fix a bug in conversion of File into raw handle --- src/fs/file.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/fs/file.rs b/src/fs/file.rs index 3b20bbb..4febb4c 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -419,7 +419,11 @@ cfg_if! { impl IntoRawFd for File { fn into_raw_fd(self) -> RawFd { - self.file.as_raw_fd() + let file = self.file.clone(); + drop(self); + Arc::try_unwrap(file) + .expect("cannot acquire ownership of file handle after drop") + .into_raw_fd() } } } @@ -442,7 +446,11 @@ cfg_if! { impl IntoRawHandle for File { fn into_raw_handle(self) -> RawHandle { - self.file.as_raw_handle() + let file = self.file.clone(); + drop(self); + Arc::try_unwrap(file) + .expect("cannot acquire ownership of file's handle after drop") + .into_raw_handle() } } }