Fix the memory leak on large heap slot dealloc

This commit is contained in:
Zhang Junyang 2025-05-08 16:02:15 +08:00 committed by Tate, Hongliang Tian
parent 3a1314296d
commit d3e4f175cd
2 changed files with 3 additions and 2 deletions

View File

@ -116,6 +116,8 @@ impl<M: AnyFrameMeta> Segment<M> {
/// It could be manually forgotten by [`core::mem::forget`],
/// [`ManuallyDrop`], or [`Self::into_raw`].
pub(crate) unsafe fn from_raw(range: Range<Paddr>) -> Self {
debug_assert_eq!(range.start % PAGE_SIZE, 0);
debug_assert_eq!(range.end % PAGE_SIZE, 0);
Self {
range,
_marker: core::marker::PhantomData,

View File

@ -116,8 +116,7 @@ impl HeapSlot {
debug_assert_eq!(size % PAGE_SIZE, 0);
debug_assert_eq!(self.paddr() % PAGE_SIZE, 0);
let nframes = size / PAGE_SIZE;
let range = self.paddr()..self.paddr() + nframes;
let range = self.paddr()..self.paddr() + size;
// SAFETY: The segment was once forgotten when allocated.
drop(unsafe { Segment::<LargeAllocFrameMeta>::from_raw(range) });