about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristiaan Dirkx <christiaan@dirkx.email>2021-04-18 05:13:53 +0200
committerChristiaan Dirkx <christiaan@dirkx.email>2021-04-22 18:00:17 +0200
commit8aeea227daf4a78761c41bb32321e8b2e505d27e (patch)
treead6a6afba1f9e653bfb0a610a1ed97145389c1d1
parent11445c10ab630a6ad8526f3fc5bcea1badad2964 (diff)
downloadrust-8aeea227daf4a78761c41bb32321e8b2e505d27e.tar.gz
rust-8aeea227daf4a78761c41bb32321e8b2e505d27e.zip
Apply suggestions from review
-rw-r--r--library/std/src/sys/unix/mod.rs4
-rw-r--r--library/std/src/sys/windows/net.rs13
-rw-r--r--library/std/src/sys_common/rt.rs4
3 files changed, 12 insertions, 9 deletions
diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs
index bd9ac32b0d2..8ae0c1120ff 100644
--- a/library/std/src/sys/unix/mod.rs
+++ b/library/std/src/sys/unix/mod.rs
@@ -64,10 +64,10 @@ pub unsafe fn init(argc: isize, argv: *const *const u8) {
     args::init(argc, argv);
 
     unsafe fn sanitize_standard_fds() {
+        #[cfg(not(miri))]
+        // The standard fds are always available in Miri.
         cfg_if::cfg_if! {
             if #[cfg(not(any(
-                // The standard fds are always available in Miri.
-                miri,
                 target_os = "emscripten",
                 target_os = "fuchsia",
                 target_os = "vxworks",
diff --git a/library/std/src/sys/windows/net.rs b/library/std/src/sys/windows/net.rs
index f577169e0e0..1ad13254c08 100644
--- a/library/std/src/sys/windows/net.rs
+++ b/library/std/src/sys/windows/net.rs
@@ -26,12 +26,12 @@ pub mod netc {
 
 pub struct Socket(c::SOCKET);
 
+static INIT: Once = Once::new();
+
 /// Checks whether the Windows socket interface has been started already, and
 /// if not, starts it.
 pub fn init() {
-    static START: Once = Once::new();
-
-    START.call_once(|| unsafe {
+    INIT.call_once(|| unsafe {
         let mut data: c::WSADATA = mem::zeroed();
         let ret = c::WSAStartup(
             0x202, // version 2.2
@@ -42,8 +42,11 @@ pub fn init() {
 }
 
 pub fn cleanup() {
-    unsafe {
-        c::WSACleanup();
+    if INIT.is_completed() {
+        // only close the socket interface if it has actually been started
+        unsafe {
+            c::WSACleanup();
+        }
     }
 }
 
diff --git a/library/std/src/sys_common/rt.rs b/library/std/src/sys_common/rt.rs
index dc20cf0e14a..5906b4e3e0e 100644
--- a/library/std/src/sys_common/rt.rs
+++ b/library/std/src/sys_common/rt.rs
@@ -29,10 +29,10 @@ pub fn init(argc: isize, argv: *const *const u8) {
 pub fn cleanup() {
     static CLEANUP: Once = Once::new();
     CLEANUP.call_once(|| unsafe {
-        // SAFETY: Only called once during runtime cleanup.
-        sys::cleanup();
         // Flush stdout and disable buffering.
         crate::io::cleanup();
+        // SAFETY: Only called once during runtime cleanup.
+        sys::cleanup();
     });
 }