Skip to content

Commit

Permalink
kmm_map.c: Remember to free the temporary 'pages' variable
Browse files Browse the repository at this point in the history
The temp variable was freed only in error cases, but it needs to be freed
in the happy case as well.
  • Loading branch information
pussuw committed Oct 9, 2023
1 parent 1b15b1c commit 9b50f65
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mm/kmap/kmm_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ void kmm_unmap(FAR void *kaddr)

FAR void *kmm_map_user(FAR void *uaddr, size_t size)
{
FAR void *pages;
FAR void **pages;
uintptr_t vaddr;
uintptr_t offset;
size_t npages;
Expand Down Expand Up @@ -414,30 +414,31 @@ FAR void *kmm_map_user(FAR void *uaddr, size_t size)

/* No, the area must be mapped into kernel virtual address space */

pages = kmm_zalloc(npages * sizeof(FAR void *));
pages = (FAR void **)kmm_zalloc(npages * sizeof(FAR void *));
if (!pages)
{
return NULL;
}

/* Fetch the physical pages for the user virtual address range */

ret = get_user_pages(&pages, npages, vaddr);
ret = get_user_pages(pages, npages, vaddr);
if (ret < 0)
{
goto errout_with_pages;
}

/* Map the physical pages to kernel memory */

vaddr = (uintptr_t)map_pages(&pages, npages, PROT_READ | PROT_WRITE);
vaddr = (uintptr_t)map_pages(pages, npages, PROT_READ | PROT_WRITE);
if (!vaddr)
{
goto errout_with_pages;
}

/* Ok, we have a virtual memory area, add the offset back */

kmm_free(pages);
return (FAR void *)(vaddr + offset);

errout_with_pages:
Expand Down

0 comments on commit 9b50f65

Please sign in to comment.