alloc_system: Handle failure properly

The Unix implementation was incorrectly handling failure for reallocation of
over-aligned types by not checking for NULL.

Closes #32993
This commit is contained in:
Alex Crichton
2016-04-15 10:02:21 -07:00
parent 74b3684d00
commit 99c0547854

View File

@@ -96,8 +96,10 @@ mod imp {
libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8 libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8
} else { } else {
let new_ptr = allocate(size, align); let new_ptr = allocate(size, align);
ptr::copy(ptr, new_ptr, cmp::min(size, old_size)); if !new_ptr.is_null() {
deallocate(ptr, old_size, align); ptr::copy(ptr, new_ptr, cmp::min(size, old_size));
deallocate(ptr, old_size, align);
}
new_ptr new_ptr
} }
} }