From 6750605a615bf70d79db5cb8df0793dfdd860b2b Mon Sep 17 00:00:00 2001 From: Peter Huene Date: Tue, 10 Dec 2019 23:03:36 -0800 Subject: [PATCH] Fix AppVerifier check regarding invalid call to VirtualFree. (#697) Calls to `VirtualFree` that pass `MEM_RELEASE` must specify a size of 0 as the OS will be freeing the original range for the given base address. The calls to free `MMap` memory on Windows were silently failing because of an incorrect assertion (on Windows, `VirtualFree` returns non-zero for success). This was caught via AppVerifier while investigating a heap overrun issue on a different PR. --- crates/runtime/src/mmap.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/runtime/src/mmap.rs b/crates/runtime/src/mmap.rs index 32acabbd86..a5387f8705 100644 --- a/crates/runtime/src/mmap.rs +++ b/crates/runtime/src/mmap.rs @@ -255,8 +255,8 @@ impl Drop for Mmap { use winapi::ctypes::c_void; use winapi::um::memoryapi::VirtualFree; use winapi::um::winnt::MEM_RELEASE; - let r = unsafe { VirtualFree(self.ptr as *mut c_void, self.len, MEM_RELEASE) }; - assert_eq!(r, 0); + let r = unsafe { VirtualFree(self.ptr as *mut c_void, 0, MEM_RELEASE) }; + assert_ne!(r, 0); } } }