Free pgdir in setupkvm in case of mappages failure

There is a potential memory leak when mappages() fails inside setupkvm().
A call to freevm() is added in this case so as to reclaim the lost mapping pages.
This commit is contained in:
Saarett 2017-02-05 12:44:56 +02:00 committed by GitHub
parent 59cdd6c63b
commit 03b3086327

4
vm.c
View file

@ -137,8 +137,10 @@ setupkvm(void)
panic("PHYSTOP too high");
for(k = kmap; k < &kmap[NELEM(kmap)]; k++)
if(mappages(pgdir, k->virt, k->phys_end - k->phys_start,
(uint)k->phys_start, k->perm) < 0)
(uint)k->phys_start, k->perm) < 0) {
freevm(pgdir);
return 0;
}
return pgdir;
}