]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
mmap/mmap: Fix resource leak
authorAlec Brown <alec.r.brown@oracle.com>
Mon, 17 Nov 2025 07:11:14 +0000 (07:11 +0000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 18 Nov 2025 13:34:44 +0000 (14:34 +0100)
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>
grub-core/mmap/mmap.c

index 8f03b7765330cf3a2919665f5af5a53719d90398..7c7d3911c7de8c46f7ecacb5cfafeaaaa0ac883d 100644 (file)
@@ -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;