Print out the error when HeapFree failures do occur

This commit is contained in:
Peter Atashian 2016-10-25 10:00:16 -04:00
parent affc3b7552
commit b3e8c4c2be
No known key found for this signature in database
GPG Key ID: DE04D9E27559BC8A

View File

@ -166,6 +166,7 @@ mod imp {
fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> LPVOID; fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> LPVOID;
fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID, dwBytes: SIZE_T) -> LPVOID; fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID, dwBytes: SIZE_T) -> LPVOID;
fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL; fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL;
fn GetLastError() -> DWORD;
} }
#[repr(C)] #[repr(C)]
@ -230,11 +231,11 @@ pub unsafe fn reallocate_inplace(ptr: *mut u8,
pub unsafe fn deallocate(ptr: *mut u8, _old_size: usize, align: usize) { pub unsafe fn deallocate(ptr: *mut u8, _old_size: usize, align: usize) {
if align <= MIN_ALIGN { if align <= MIN_ALIGN {
let err = HeapFree(GetProcessHeap(), 0, ptr as LPVOID); let err = HeapFree(GetProcessHeap(), 0, ptr as LPVOID);
debug_assert!(err != 0); debug_assert!(err != 0, "Failed to free heap memory: {}", GetLastError());
} else { } else {
let header = get_header(ptr); let header = get_header(ptr);
let err = HeapFree(GetProcessHeap(), 0, header.0 as LPVOID); let err = HeapFree(GetProcessHeap(), 0, header.0 as LPVOID);
debug_assert!(err != 0); debug_assert!(err != 0, "Failed to free heap memory: {}", GetLastError());
} }
} }