Skip to content

Commit 752a2cc

Browse files
committed
fix(deallocate_middle): skip to next in try_insert_after
If the next hole node is still lower than the hole to be added, skip 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 <[email protected]>
1 parent cf6a569 commit 752a2cc

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/hole.rs

+5
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,11 @@ impl Cursor {
435435

436436
// If we have a next, does the node overlap next?
437437
if let Some(next) = self.current().next.as_ref() {
438+
if next < &node {
439+
// advance the list more
440+
return Err(());
441+
}
442+
438443
let node_u8 = node_u8 as *const u8;
439444
assert!(
440445
node_u8.wrapping_add(node_size) <= next.as_ptr().cast::<u8>(),

src/test.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,10 @@ fn deallocate_middle() {
151151
heap.deallocate(z, layout.clone());
152152
assert_eq!((*(x.as_ptr() as *const Hole)).size, size);
153153
assert_eq!((*(z.as_ptr() as *const Hole)).size, size);
154-
heap.deallocate(y, layout.clone());
155-
assert_eq!((*(x.as_ptr() as *const Hole)).size, size * 3);
156154
heap.deallocate(a, layout.clone());
155+
assert_eq!((*(x.as_ptr() as *const Hole)).size, size);
156+
assert_eq!((*(z.as_ptr() as *const Hole)).size, heap.size - 2 * size);
157+
heap.deallocate(y, layout.clone());
157158
assert_eq!((*(x.as_ptr() as *const Hole)).size, heap.size);
158159
}
159160
}

0 commit comments

Comments
 (0)