]> git.lizzy.rs Git - rust.git/blobdiff - library/std/src/sys/windows/net.rs
Apply suggestions from review
[rust.git] / library / std / src / sys / windows / net.rs
index f577169e0e0ec725f4b4146e3e5617ffc3003536..1ad13254c0846f2e27bfd0a4793b906211ef991f 100644 (file)
@@ -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();
+        }
     }
 }