Skip to content

Commit

Permalink
alloc_system: Handle failure properly
Browse files Browse the repository at this point in the history
The Unix implementation was incorrectly handling failure for reallocation of
over-aligned types by not checking for NULL.

Closes #32993
  • Loading branch information
alexcrichton committed Apr 15, 2016
1 parent 74b3684 commit 99c0547
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/liballoc_system/lib.rs
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 99c0547

Please sign in to comment.