Skip to content

Commit 99c0547

Browse files
committed
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
1 parent 74b3684 commit 99c0547

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/liballoc_system/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ mod imp {
9696
libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8
9797
} else {
9898
let new_ptr = allocate(size, align);
99-
ptr::copy(ptr, new_ptr, cmp::min(size, old_size));
100-
deallocate(ptr, old_size, align);
99+
if !new_ptr.is_null() {
100+
ptr::copy(ptr, new_ptr, cmp::min(size, old_size));
101+
deallocate(ptr, old_size, align);
102+
}
101103
new_ptr
102104
}
103105
}

0 commit comments

Comments
 (0)