From c58411a08e91be07c43e520bfd546b624f85b46c Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Wed, 29 Jun 2022 12:03:30 +0200 Subject: [PATCH] fix(deallocate_middle): advance to next in try_insert_after If the next hole node is still lower than the hole to be added, advance the cursor to the next in the list. For this to trigger, this patch modifies the `deallocate_middle()` test. It requires two holes in the list before the one to be deallocated. Signed-off-by: Harald Hoyer --- src/hole.rs | 5 +++++ src/test.rs | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/hole.rs b/src/hole.rs index 5c25649..a095338 100644 --- a/src/hole.rs +++ b/src/hole.rs @@ -435,6 +435,11 @@ impl Cursor { // If we have a next, does the node overlap next? if let Some(next) = self.current().next.as_ref() { + if next < &node { + // advance the list more + return Err(()); + } + let node_u8 = node_u8 as *const u8; assert!( node_u8.wrapping_add(node_size) <= next.as_ptr().cast::(), diff --git a/src/test.rs b/src/test.rs index f61bc10..5718410 100644 --- a/src/test.rs +++ b/src/test.rs @@ -151,9 +151,10 @@ fn deallocate_middle() { heap.deallocate(z, layout.clone()); assert_eq!((*(x.as_ptr() as *const Hole)).size, size); assert_eq!((*(z.as_ptr() as *const Hole)).size, size); - heap.deallocate(y, layout.clone()); - assert_eq!((*(x.as_ptr() as *const Hole)).size, size * 3); heap.deallocate(a, layout.clone()); + assert_eq!((*(x.as_ptr() as *const Hole)).size, size); + assert_eq!((*(z.as_ptr() as *const Hole)).size, heap.size - 2 * size); + heap.deallocate(y, layout.clone()); assert_eq!((*(x.as_ptr() as *const Hole)).size, heap.size); } }