Browse Source

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.
pull/700/head
Peter Huene 5 years ago
committed by Alex Crichton
parent
commit
6750605a61
  1. 4
      crates/runtime/src/mmap.rs

4
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);
}
}
}

Loading…
Cancel
Save