@@ -265,6 +265,17 @@ impl<'tcx> MainThreadState<'tcx> {
265
265
// Deal with our thread-local memory. We do *not* want to actually free it, instead we consider TLS
266
266
// to be like a global `static`, so that all memory reached by it is considered to "not leak".
267
267
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
+
268
279
// Stop interpreter loop.
269
280
throw_machine_stop ! ( TerminationInfo :: Exit { code: exit_code, leak_check: true } ) ;
270
281
}
@@ -467,16 +478,6 @@ pub fn eval_entry<'tcx>(
467
478
468
479
// If we get here there was no fatal error.
469
480
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
-
480
481
// Possibly check for memory leaks.
481
482
if leak_check && !ignore_leaks {
482
483
// Check for thread leaks.
0 commit comments