Rollup merge of #32997 - alexcrichton:fix-alloc-system-how-did-this-land, r=nagisa

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:
Manish Goregaokar 2016-04-16 01:16:45 +05:30
commit e563359396
No known key found for this signature in database
GPG Key ID: 3BBF4D3E2EF79F98

View File

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