From 2464d43829588909cc6c69027c7d965000e632c1 Mon Sep 17 00:00:00 2001 From: Alec Brown Date: Mon, 17 Nov 2025 07:11:14 +0000 Subject: [PATCH] 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 Reviewed-by: Sudhakar Kuppusamy Reviewed-by: Daniel Kiper --- grub-core/mmap/mmap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c index 8f03b7765..7c7d3911c 100644 --- a/grub-core/mmap/mmap.c +++ b/grub-core/mmap/mmap.c @@ -242,8 +242,12 @@ grub_mmap_iterate (grub_memory_hook_t hook, void *hook_data) else { struct mm_list *n = grub_malloc (sizeof (*n)); - if (n == NULL) - return grub_errno; + if (n == NULL) + { + grub_free (ctx.scanline_events); + grub_free (present); + return grub_errno; + } n->val = ctx.scanline_events[i].memtype; n->present = 1;