diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 05b21eeb40f71..1fac8f997da05 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -623,13 +623,7 @@ pub fn stdout() -> Stdout { // by replacing the line writer by one with zero // buffering capacity. pub fn cleanup() { - let mut initialized = false; - let stdout = STDOUT.get_or_init(|| { - initialized = true; - ReentrantMutex::new(RefCell::new(LineWriter::with_capacity(0, stdout_raw()))) - }); - - if !initialized { + if let Some(stdout) = STDOUT.get() { // The buffer was previously initialized, overwrite it here. // We use try_lock() instead of lock(), because someone // might have leaked a StdoutLock, which would diff --git a/library/std/src/rt.rs b/library/std/src/rt.rs index 335944845ae0b..8e0a5f3dc8e05 100644 --- a/library/std/src/rt.rs +++ b/library/std/src/rt.rs @@ -111,11 +111,11 @@ unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) { // NOTE: this is not guaranteed to run, for example when the program aborts. pub(crate) fn cleanup() { static CLEANUP: Once = Once::new(); - CLEANUP.call_once(|| unsafe { + CLEANUP.call_once(|| { // Flush stdout and disable buffering. crate::io::cleanup(); // SAFETY: Only called once during runtime cleanup. - sys::cleanup(); + unsafe { sys::cleanup() }; }); }