about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2025-04-29 15:38:29 +0000
committerGitHub <noreply@github.com>2025-04-29 15:38:29 +0000
commit63edce000c2d22fa12d38e75dbe26350bb2be076 (patch)
tree9c9e66342d5197a4f6b3eeb153214646cc90db70 /src/tools
parent929117e9a688601700ceb749750a8d5b55a68437 (diff)
parent47e111a03c543859010cc7677617cd940ea42753 (diff)
downloadrust-63edce000c2d22fa12d38e75dbe26350bb2be076.tar.gz
rust-63edce000c2d22fa12d38e75dbe26350bb2be076.zip
Merge pull request #4302 from RalfJung/env-cleanup
move EnvVars::cleanup into the main-thread-exit handler
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/miri/src/eval.rs21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/tools/miri/src/eval.rs b/src/tools/miri/src/eval.rs
index 7586b5efd4b..1ca11b05f0e 100644
--- a/src/tools/miri/src/eval.rs
+++ b/src/tools/miri/src/eval.rs
@@ -265,6 +265,17 @@ impl<'tcx> MainThreadState<'tcx> {
                 // Deal with our thread-local memory. We do *not* want to actually free it, instead we consider TLS
                 // to be like a global `static`, so that all memory reached by it is considered to "not leak".
                 this.terminate_active_thread(TlsAllocAction::Leak)?;
+
+                // Machine cleanup. Only do this if all threads have terminated; threads that are still running
+                // might cause Stacked Borrows errors (https://github.com/rust-lang/miri/issues/2396).
+                if this.have_all_terminated() {
+                    // Even if all threads have terminated, we have to beware of data races since some threads
+                    // might not have joined the main thread (https://github.com/rust-lang/miri/issues/2020,
+                    // https://github.com/rust-lang/miri/issues/2508).
+                    this.allow_data_races_all_threads_done();
+                    EnvVars::cleanup(this).expect("error during env var cleanup");
+                }
+
                 // Stop interpreter loop.
                 throw_machine_stop!(TerminationInfo::Exit { code: exit_code, leak_check: true });
             }
@@ -467,16 +478,6 @@ pub fn eval_entry<'tcx>(
 
     // If we get here there was no fatal error.
 
-    // Machine cleanup. Only do this if all threads have terminated; threads that are still running
-    // might cause Stacked Borrows errors (https://github.com/rust-lang/miri/issues/2396).
-    if ecx.have_all_terminated() {
-        // Even if all threads have terminated, we have to beware of data races since some threads
-        // might not have joined the main thread (https://github.com/rust-lang/miri/issues/2020,
-        // https://github.com/rust-lang/miri/issues/2508).
-        ecx.allow_data_races_all_threads_done();
-        EnvVars::cleanup(&mut ecx).expect("error during env var cleanup");
-    }
-
     // Possibly check for memory leaks.
     if leak_check && !ignore_leaks {
         // Check for thread leaks.