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:
commit
e563359396
@ -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);
|
||||||
|
if !new_ptr.is_null() {
|
||||||
ptr::copy(ptr, new_ptr, cmp::min(size, old_size));
|
ptr::copy(ptr, new_ptr, cmp::min(size, old_size));
|
||||||
deallocate(ptr, old_size, align);
|
deallocate(ptr, old_size, align);
|
||||||
|
}
|
||||||
new_ptr
|
new_ptr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user