mmap/mmap: Fix resource leak

In the function grub_mmap_iterate(), memory is allocated to
"ctx.scanline_events" and "present" but isn't freed when error handling
grub_malloc(). Prior to returning grub_errno, these variables should be
freed to prevent a resource leak.

Fixes: CID 96655

Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Alec Brown 2025-11-17 07:11:14 +00:00 committed by Daniel Kiper
parent f7bcca3168
commit 2464d43829

View File

@ -243,7 +243,11 @@ grub_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
{ {
struct mm_list *n = grub_malloc (sizeof (*n)); struct mm_list *n = grub_malloc (sizeof (*n));
if (n == NULL) if (n == NULL)
{
grub_free (ctx.scanline_events);
grub_free (present);
return grub_errno; return grub_errno;
}
n->val = ctx.scanline_events[i].memtype; n->val = ctx.scanline_events[i].memtype;
n->present = 1; n->present = 1;