Skip to content

Commit 63edce0

Browse files
authored
Merge pull request rust-lang#4302 from RalfJung/env-cleanup
move EnvVars::cleanup into the main-thread-exit handler
2 parents 929117e + 47e111a commit 63edce0

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/tools/miri/src/eval.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,17 @@ impl<'tcx> MainThreadState<'tcx> {
265265
// Deal with our thread-local memory. We do *not* want to actually free it, instead we consider TLS
266266
// to be like a global `static`, so that all memory reached by it is considered to "not leak".
267267
this.terminate_active_thread(TlsAllocAction::Leak)?;
268+
269+
// Machine cleanup. Only do this if all threads have terminated; threads that are still running
270+
// might cause Stacked Borrows errors (https://github.com/rust-lang/miri/issues/2396).
271+
if this.have_all_terminated() {
272+
// Even if all threads have terminated, we have to beware of data races since some threads
273+
// might not have joined the main thread (https://github.com/rust-lang/miri/issues/2020,
274+
// https://github.com/rust-lang/miri/issues/2508).
275+
this.allow_data_races_all_threads_done();
276+
EnvVars::cleanup(this).expect("error during env var cleanup");
277+
}
278+
268279
// Stop interpreter loop.
269280
throw_machine_stop!(TerminationInfo::Exit { code: exit_code, leak_check: true });
270281
}
@@ -467,16 +478,6 @@ pub fn eval_entry<'tcx>(
467478

468479
// If we get here there was no fatal error.
469480

470-
// Machine cleanup. Only do this if all threads have terminated; threads that are still running
471-
// might cause Stacked Borrows errors (https://github.com/rust-lang/miri/issues/2396).
472-
if ecx.have_all_terminated() {
473-
// Even if all threads have terminated, we have to beware of data races since some threads
474-
// might not have joined the main thread (https://github.com/rust-lang/miri/issues/2020,
475-
// https://github.com/rust-lang/miri/issues/2508).
476-
ecx.allow_data_races_all_threads_done();
477-
EnvVars::cleanup(&mut ecx).expect("error during env var cleanup");
478-
}
479-
480481
// Possibly check for memory leaks.
481482
if leak_check && !ignore_leaks {
482483
// Check for thread leaks.

0 commit comments

Comments
 (0)