File tree Expand file tree Collapse file tree 3 files changed +12
-9
lines changed Expand file tree Collapse file tree 3 files changed +12
-9
lines changed Original file line number Diff line number Diff 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" ,
Original file line number Diff line number Diff line change @@ -26,12 +26,12 @@ pub mod netc {
2626
2727pub 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.
3133pub 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
4444pub 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
Original file line number Diff line number Diff line change @@ -29,10 +29,10 @@ pub fn init(argc: isize, argv: *const *const u8) {
2929pub 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
You can’t perform that action at this time.
0 commit comments