diff --git a/src/hyperlight_host/src/hypervisor/virtual_machine/whp.rs b/src/hyperlight_host/src/hypervisor/virtual_machine/whp.rs index 350607cd3..8a3448a50 100644 --- a/src/hyperlight_host/src/hypervisor/virtual_machine/whp.rs +++ b/src/hyperlight_host/src/hypervisor/virtual_machine/whp.rs @@ -1360,11 +1360,6 @@ impl WhpVm { impl Drop for WhpVm { fn drop(&mut self) { - // Clean up any remaining file mappings that weren't explicitly unmapped. - for (handle, view) in self.file_mappings.drain(..) { - release_file_mapping(view, handle); - } - // Stop the software timer thread before tearing down the partition. #[cfg(feature = "hw-interrupts")] if let Some(mut t) = self.timer.take() { @@ -1379,6 +1374,11 @@ impl Drop for WhpVm { if let Err(e) = unsafe { WHvDeletePartition(self.partition) } { tracing::error!("Failed to delete partition: {}", e); } + + // Clean up any remaining file mappings that weren't explicitly unmapped. + for (handle, view) in self.file_mappings.drain(..) { + release_file_mapping(view, handle); + } } }