Skip to content

Commit

Permalink
Rollup merge of #37399 - retep998:heap-of-trouble, r=alexcrichton
Browse files Browse the repository at this point in the history
Print out the error when HeapFree failures do occur

cc #37395

I'd prefer to use `assert!` instead of `debug_assert!` if the cost is acceptable.

r? @alexcrichton
  • Loading branch information
Manishearth committed Oct 26, 2016
2 parents 960f73b + b3e8c4c commit 366d139
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/liballoc_system/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ mod imp {
fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, 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 GetLastError() -> DWORD;
}

#[repr(C)]
Expand Down Expand Up @@ -230,11 +231,11 @@ mod imp {
pub unsafe fn deallocate(ptr: *mut u8, _old_size: usize, align: usize) {
if align <= MIN_ALIGN {
let err = HeapFree(GetProcessHeap(), 0, ptr as LPVOID);
debug_assert!(err != 0);
debug_assert!(err != 0, "Failed to free heap memory: {}", GetLastError());
} else {
let header = get_header(ptr);
let err = HeapFree(GetProcessHeap(), 0, header.0 as LPVOID);
debug_assert!(err != 0);
debug_assert!(err != 0, "Failed to free heap memory: {}", GetLastError());
}
}

Expand Down

0 comments on commit 366d139

Please sign in to comment.