Skip to content

Commit 538ab1c

Browse files
committed
Consider regions that lead to very small back paddings as unsuitable
If the resulting back padding is too small to be stored as a hole, we treat the hole as unsuitable for the allocation. This way, we avoid unrecoverable leaks of that back padding, which can add up over time and fragment the heap.
1 parent 9e5878a commit 538ab1c

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/hole.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,7 @@ impl Cursor {
120120
alloc_ptr = aligned_addr;
121121
alloc_size = required_size;
122122

123-
// Okay, time to move onto the back padding. Here, we are opportunistic -
124-
// if it fits, we sits. Otherwise we just skip adding the back padding, and
125-
// sort of assume that the allocation is actually a bit larger than it
126-
// actually needs to be.
123+
// Okay, time to move onto the back padding.
127124
//
128125
// NOTE: Because we always use `HoleList::align_layout`, the size of
129126
// the new allocation is always "rounded up" to cover any partial gaps that
@@ -141,10 +138,9 @@ impl Cursor {
141138
size: (hole_end as usize) - (back_padding_start as usize),
142139
})
143140
} else {
144-
// No, it does not. We are now pretending the allocation now
145-
// holds the extra 0..size_of::<Hole>() bytes that are not
146-
// big enough to hold what SHOULD be back_padding
147-
None
141+
// No, it does not. We don't want to leak any heap bytes, so we
142+
// consider this hole unsuitable for the requested allocation.
143+
return Err(self);
148144
};
149145
}
150146

0 commit comments

Comments
 (0)