Skip to content

Commit 41f345d

Browse files
author
Stjepan Glavina
committed
Fix a bug in conversion of File into raw handle
1 parent 9bf06ce commit 41f345d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/fs/file.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,11 @@ cfg_if! {
419419

420420
impl IntoRawFd for File {
421421
fn into_raw_fd(self) -> RawFd {
422-
self.file.as_raw_fd()
422+
let file = self.file.clone();
423+
drop(self);
424+
Arc::try_unwrap(file)
425+
.expect("cannot acquire ownership of file handle after drop")
426+
.into_raw_fd()
423427
}
424428
}
425429
}
@@ -442,7 +446,11 @@ cfg_if! {
442446

443447
impl IntoRawHandle for File {
444448
fn into_raw_handle(self) -> RawHandle {
445-
self.file.as_raw_handle()
449+
let file = self.file.clone();
450+
drop(self);
451+
Arc::try_unwrap(file)
452+
.expect("cannot acquire ownership of file's handle after drop")
453+
.into_raw_handle()
446454
}
447455
}
448456
}

0 commit comments

Comments
 (0)