]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
fix(mm): munmap/brk page leaks — free physical frames on unmap, rollback on partial...
authorTulio A M Mendes <[email protected]>
Fri, 17 Apr 2026 04:09:18 +0000 (01:09 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 17 Apr 2026 04:09:18 +0000 (01:09 -0300)
commit2263b4617434f333b33d049ce0025ff09cc58a81
tree5c463e8110901fd75142df020e952f836889f3e3
parentb20666de9e9899ce197a43e215684da0f81b22ad
fix(mm): munmap/brk page leaks — free physical frames on unmap, rollback on partial failure

1. munmap: vmm_unmap_page only clears PTEs without freeing physical
   frames. For anonymous mmaps (shmid == -1), call vmm_virt_to_phys +
   pmm_free_page before vmm_unmap_page. Device-backed/shared mappings
   keep their frames (managed by their own subsystems).

2. brk shrink: same leak — free physical frames before unmapping when
   the heap shrinks.

3. brk grow partial failure: if pmm_alloc_page fails mid-expansion,
   rollback all pages already mapped in this call (unmap + free), then
   return old heap_break. Previously these pages were leaked permanently.

4. mmap anonymous partial failure: same rollback pattern applied to
   syscall_mmap_impl — if pmm_alloc_page fails mid-allocation, unmap
   and free all pages already mapped before returning -ENOMEM.

All tests pass: 69/69 host + 103/103 QEMU, zero regressions.
src/kernel/syscall.c