]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
lib/reloacator: Fix memory leaks
authorLidong Chen <lidong.chen@oracle.com>
Thu, 27 Mar 2025 17:56:32 +0000 (17:56 +0000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Fri, 4 Apr 2025 17:31:05 +0000 (19:31 +0200)
Fix memory leaks in grub_relocator_alloc_chunk_align().

Fixes: CID 473844
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/lib/relocator.c

index e0478ae5ba33bc17eee6f87f268bd6a79ce19ca9..3306a1bb7ad90f1550d21f22a185e6a264f1daa9 100644 (file)
@@ -1440,6 +1440,7 @@ grub_relocator_alloc_chunk_align (struct grub_relocator *rel,
          break;
        }
 
+      grub_free (ctx.chunk);
       return grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
     }
   while (0);
@@ -1456,7 +1457,10 @@ grub_relocator_alloc_chunk_align (struct grub_relocator *rel,
     grub_mmap_iterate (grub_relocator_alloc_chunk_align_iter, &ctx);
 #endif
     if (!ctx.found)
-      return grub_error (GRUB_ERR_BAD_OS, "couldn't find suitable memory target");
+      {
+       grub_free (ctx.chunk);
+       return grub_error (GRUB_ERR_BAD_OS, "couldn't find suitable memory target");
+      }
   }
   while (1)
     {