Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't initialize stdout during io cleanup #119394

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions library/std/src/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() };
});
}

Expand Down
Loading