Skip to content

Commit 11187ef

Browse files
committed
fix a bug in windows
1 parent 522f888 commit 11187ef

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

src/fd_ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use pyo3::prelude::*;
1010
mod windows;
1111
#[cfg(windows)]
1212
pub use self::windows::{
13-
duplicate_handle, duplicate_handle_from_fd, duplicate_tcp_stream, poll_fd, raw_fd_to_handle,
13+
duplicate_handle, duplicate_handle_from_fd, duplicate_tcp_stream, poll_fd,
1414
};
1515

1616
pub type RawFd = i64;

src/fd_ops/windows.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ pub fn duplicate_handle(handle: HANDLE) -> io::Result<HANDLE> {
8585
}
8686

8787
let mut duplicated = 0 as HANDLE;
88-
let ok = duplicate_handle_raw(
89-
GetCurrentProcess(),
90-
handle,
91-
&mut duplicated,
92-
DUPLICATE_SAME_ACCESS,
93-
);
88+
// SAFETY: `GetCurrentProcess` returns the always-valid pseudo-handle for the current
89+
// process and does not require any cleanup by the caller.
90+
let process = unsafe { GetCurrentProcess() };
91+
let ok = duplicate_handle_raw(process, handle, &mut duplicated, DUPLICATE_SAME_ACCESS);
9492
if ok == 0 {
9593
return Err(io::Error::last_os_error());
9694
}

0 commit comments

Comments
 (0)