Skip to content

Commit

Permalink
Avoid freeing outside of the heap
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc committed Nov 20, 2023
1 parent d02032e commit 55ec23f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/sys/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,13 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
pub unsafe fn free(ptr: *mut u8, layout: Layout) {
let table = PROCESS_TABLE.read();
let proc = &table[id()];
proc.allocator.dealloc(ptr, layout)
let bottom = proc.allocator.lock().bottom();
let top = proc.allocator.lock().top();
if bottom <= ptr && ptr < top {
proc.allocator.dealloc(ptr, layout);
} else {
debug!("Could not free {:#?}", ptr);
}
}

/************************
Expand Down

0 comments on commit 55ec23f

Please sign in to comment.