From 54bc22acc5ec92d8e33038c943006c48538f6b54 Mon Sep 17 00:00:00 2001 From: Xu Yandong Date: Wed, 19 Mar 2025 07:42:41 +0000 Subject: [PATCH] address_space: check munmap return value Signed-off-by: Xu Yandong --- address_space/src/host_mmap.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/address_space/src/host_mmap.rs b/address_space/src/host_mmap.rs index d31d4fd34..46eaf39e5 100644 --- a/address_space/src/host_mmap.rs +++ b/address_space/src/host_mmap.rs @@ -482,10 +482,17 @@ impl Drop for HostMemMapping { /// Release the memory mapping. fn drop(&mut self) { // SAFETY: self.host_addr and self.size has already been verified during initialization. - unsafe { + let ret = unsafe { libc::munmap( self.host_addr as *mut libc::c_void, self.size() as libc::size_t, + ) + }; + + if ret < 0 { + error!( + "Failed to release memory mapping, error: {:?}", + std::io::Error::last_os_error() ); } } -- Gitee