Fix memory leaks in grub_relocator_alloc_chunk_align().

Fixes: CID 473844

Signed-off-by: Lidong Chen <lidong.c...@oracle.com>
---
 grub-core/lib/relocator.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c
index e0478ae5b..3306a1bb7 100644
--- a/grub-core/lib/relocator.c
+++ b/grub-core/lib/relocator.c
@@ -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)
     {
-- 
2.34.1


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to