Skip to content

Commit

Permalink
Rollup merge of #32997 - alexcrichton:fix-alloc-system-how-did-this-l…
Browse files Browse the repository at this point in the history
…and, 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
  • Loading branch information
Manishearth committed Apr 15, 2016
2 parents eba8055 + 99c0547 commit e563359
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/liballoc_system/lib.rs
Original file line number Diff line number Diff line change
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 e563359

Please sign in to comment.