Skip to content

Commit ca143a8

Browse files
authored
Merge pull request #9256 from zhang2014/fix/memory_lost
fix(base): fix memory lost when mmap alloc panic
2 parents 6041a49 + adc45c6 commit ca143a8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/common/base/src/mem_allocator/mmap_allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ pub mod linux {
5151
#[inline(always)]
5252
fn mmap_alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
5353
debug_assert!(layout.align() <= page_size());
54+
ThreadTracker::alloc(layout.size() as i64);
5455
const PROT: i32 = libc::PROT_READ | libc::PROT_WRITE;
5556
const FLAGS: i32 = libc::MAP_PRIVATE | libc::MAP_ANONYMOUS | libc::MAP_POPULATE;
5657
let addr = unsafe { libc::mmap(null_mut(), layout.size(), PROT, FLAGS, -1, 0) };
5758
if addr == libc::MAP_FAILED {
5859
return Err(AllocError);
5960
}
6061
let addr = NonNull::new(addr as *mut ()).ok_or(AllocError)?;
61-
ThreadTracker::alloc(layout.size() as i64);
6262
Ok(NonNull::<[u8]>::from_raw_parts(addr, layout.size()))
6363
}
6464

0 commit comments

Comments
 (0)