Skip to content

Commit

Permalink
[HeapAllocator::allocate_segment] handle case when alloc_zeroed() ret…
Browse files Browse the repository at this point in the history
…urns null
  • Loading branch information
dwrensha committed Sep 20, 2022
1 parent 8b8c5ec commit 8c9d41b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions capnp/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,10 @@ impl HeapAllocator {
unsafe impl Allocator for HeapAllocator {
fn allocate_segment(&mut self, minimum_size: u32) -> (*mut u8, u32) {
let size = core::cmp::max(minimum_size, self.next_size);
let ptr = unsafe {
alloc::alloc::alloc_zeroed(alloc::alloc::Layout::from_size_align(size as usize * BYTES_PER_WORD, 8).unwrap())
};
let layout = alloc::alloc::Layout::from_size_align(size as usize * BYTES_PER_WORD,
8).unwrap();
let ptr = unsafe { alloc::alloc::alloc_zeroed(layout) };
if ptr.is_null() { alloc::alloc::handle_alloc_error(layout); }
match self.allocation_strategy {
AllocationStrategy::GrowHeuristically => {
if size < self.max_segment_words - self.next_size {
Expand All @@ -627,7 +628,6 @@ unsafe impl Allocator for HeapAllocator {

#[test]
fn test_allocate_max() {

let allocation_size = 1 << 24;
let mut allocator = HeapAllocator::new()
.max_segment_words((1 << 25) - 1)
Expand Down

0 comments on commit 8c9d41b

Please sign in to comment.