fix: fix memory leaks

This commit is contained in:
2026-03-04 07:41:40 +01:00
parent eb69bdb5fb
commit 624b1e7e69
5 changed files with 44 additions and 2 deletions
+4
View File
@@ -54,6 +54,7 @@ namespace Montauk {
// Track the allocation so Sys_Free can release it
int slot = GetCurrentSlot();
if (slot >= 0) Sched::g_allocatedPages[slot] += numPages;
if (slot >= 0 && g_heapAllocCount[slot] < MaxHeapAllocs) {
g_heapAllocs[slot][g_heapAllocCount[slot]++] = { userVa, numPages };
}
@@ -66,6 +67,7 @@ namespace Montauk {
static void CleanupHeapForSlot(int slot, uint64_t /*pml4Phys*/) {
if (slot < 0 || slot >= Sched::MaxProcesses) return;
g_heapAllocCount[slot] = 0;
Sched::g_allocatedPages[slot] = 0;
}
static void Sys_Free(uint64_t addr) {
@@ -98,6 +100,8 @@ namespace Montauk {
Memory::VMM::Paging::UnmapUserIn(proc->pml4Phys, pageVa);
}
if (slot >= 0) Sched::g_allocatedPages[slot] -= numPages;
// Remove tracking entry by swapping with the last element
g_heapAllocs[slot][idx] = g_heapAllocs[slot][g_heapAllocCount[slot] - 1];
g_heapAllocCount[slot]--;