Fix few issues/leaks

This commit is contained in:
Mathieu Maret 2021-11-12 10:19:43 +01:00
parent d1994d44a3
commit 9d35a686ab
3 changed files with 14 additions and 12 deletions

View File

@ -43,8 +43,10 @@ int mmuContextSetup()
ret = pageMap(initialCtx->vaddr_PD, initialCtx->paddr_PD,
PAGING_MEM_WRITE | PAGING_MEM_READ);
if (ret)
if (ret){
free(initialCtx);
return ret;
}
list_singleton(listContext, initialCtx);
currentContext = initialCtx;

View File

@ -314,7 +314,7 @@ int pagingCopyKernelSpace(vaddr_t destVaddrPD, paddr_t destPaddrPD, vaddr_t srcV
{
struct pde *src_pd = (struct pde *)srcVaddrPD;
struct pde *dest_pd = (struct pde *)destVaddrPD;
struct pde mirror_pde;
struct pde mirror_pde = {0};
uint index_in_pd;
/* Fill destination PD with zeros */

View File

@ -10,7 +10,7 @@
static struct memArea *freeArea;
static struct memArea *usedArea;
static int areaMergeFreeArea(struct memArea *prev, struct memArea *next);
static int areaMergeFreeArea(struct memArea *prev, struct memArea **next);
void areaInit(vaddr_t firstMemUsed, vaddr_t lastUsed, vaddr_t stackBottom, vaddr_t stackTop)
{
@ -214,26 +214,26 @@ int areaAdd(vaddr_t start, vaddr_t end, int isFree)
if (isFree) {
if (newArea->prev)
areaMergeFreeArea(newArea->prev, *area);
areaMergeFreeArea(newArea->prev, area);
if (newArea->next)
areaMergeFreeArea(*area, newArea->next);
areaMergeFreeArea(*area, &(newArea->next));
}
return 0;
}
static int areaMergeFreeArea(struct memArea *prev, struct memArea *next)
static int areaMergeFreeArea(struct memArea *prev, struct memArea **next)
{
if (prev->startAddr + prev->nbPages * PAGE_SIZE != next->startAddr) {
if (prev->startAddr + prev->nbPages * PAGE_SIZE != (*next)->startAddr) {
return -1;
}
prev->nbPages += next->nbPages;
list_delete(freeArea, next);
prev->nbPages += (*next)->nbPages;
list_delete(freeArea, *next);
free(next);
next = prev;
*next = prev;
return 0;
}
@ -269,10 +269,10 @@ int areaFree(vaddr_t addr)
insertSorted(&freeArea, area);
if (area->prev)
areaMergeFreeArea(area->prev, area);
areaMergeFreeArea(area->prev, &area);
if (area->next)
areaMergeFreeArea(area, area->next);
areaMergeFreeArea(area, &(area->next));
return 0;
}