Skip to content

Commit e563359

Browse files
committed
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
2 parents eba8055 + 99c0547 commit e563359

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/liballoc_system/lib.rs

+4-2
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)