Skip to content

Commit d074abf

Browse files
committed
Apply suggestions from review
1 parent 37e2152 commit d074abf

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

std/src/sys/unix/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ pub unsafe fn init(argc: isize, argv: *const *const u8) {
6464
args::init(argc, argv);
6565

6666
unsafe fn sanitize_standard_fds() {
67+
#[cfg(not(miri))]
68+
// The standard fds are always available in Miri.
6769
cfg_if::cfg_if! {
6870
if #[cfg(not(any(
69-
// The standard fds are always available in Miri.
70-
miri,
7171
target_os = "emscripten",
7272
target_os = "fuchsia",
7373
target_os = "vxworks",

std/src/sys/windows/net.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ pub mod netc {
2626

2727
pub struct Socket(c::SOCKET);
2828

29+
static INIT: Once = Once::new();
30+
2931
/// Checks whether the Windows socket interface has been started already, and
3032
/// if not, starts it.
3133
pub fn init() {
32-
static START: Once = Once::new();
33-
34-
START.call_once(|| unsafe {
34+
INIT.call_once(|| unsafe {
3535
let mut data: c::WSADATA = mem::zeroed();
3636
let ret = c::WSAStartup(
3737
0x202, // version 2.2
@@ -42,8 +42,11 @@ pub fn init() {
4242
}
4343

4444
pub fn cleanup() {
45-
unsafe {
46-
c::WSACleanup();
45+
if INIT.is_completed() {
46+
// only close the socket interface if it has actually been started
47+
unsafe {
48+
c::WSACleanup();
49+
}
4750
}
4851
}
4952

std/src/sys_common/rt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ pub fn init(argc: isize, argv: *const *const u8) {
2929
pub fn cleanup() {
3030
static CLEANUP: Once = Once::new();
3131
CLEANUP.call_once(|| unsafe {
32-
// SAFETY: Only called once during runtime cleanup.
33-
sys::cleanup();
3432
// Flush stdout and disable buffering.
3533
crate::io::cleanup();
34+
// SAFETY: Only called once during runtime cleanup.
35+
sys::cleanup();
3636
});
3737
}
3838

0 commit comments

Comments
 (0)