All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] multiboot: fix memory leak
@ 2022-11-10  7:01 t.feng
  2022-11-14 15:41 ` Daniel Kiper
  0 siblings, 1 reply; 2+ messages in thread
From: t.feng @ 2022-11-10  7:01 UTC (permalink / raw)
  To: grub-devel; +Cc: fengtao40, daniel.kiper, yanan, zhaowei23

The commit eb33e61b3 (multiboot: fix memory leak) did not fix all
issues. Fix all of them right now.

Fixes: eb33e61b3 (multiboot: fix memory leak)

Signed-off-by: "t.feng" <fengtao40@huawei.com>
---
 grub-core/loader/multiboot_elfxx.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c
index b76451f73..e067d2d84 100644
--- a/grub-core/loader/multiboot_elfxx.c
+++ b/grub-core/loader/multiboot_elfxx.c
@@ -246,10 +246,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld)
 	return grub_errno;
 
       if (grub_file_seek (mld->file, ehdr->e_shoff) == (grub_off_t) -1)
-	{
-	  grub_free (shdr);
-	  return grub_errno;
-	}
+	goto fail;
 
       if (grub_file_read (mld->file, shdr, shnum * ehdr->e_shentsize)
               != (grub_ssize_t) shnum * ehdr->e_shentsize)
@@ -257,7 +254,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld)
 	  if (!grub_errno)
 	    grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
 			mld->filename);
-	  return grub_errno;
+	  goto fail;
 	}
 
       for (shdrptr = shdr, i = 0; i < shnum;
@@ -268,7 +265,10 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld)
 	  grub_addr_t target;
 
 	  if (mld->mbi_ver >= 2 && (sh->sh_type == SHT_REL || sh->sh_type == SHT_RELA))
-	    return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "ELF files with relocs are not supported yet");
+	    {
+	      grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "ELF files with relocs are not supported yet");
+	      goto fail;
+	    }
 
 	  /* This section is a loaded section,
 	     so we don't care.  */
@@ -287,13 +287,14 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld)
 	  if (err != GRUB_ERR_NONE)
 	    {
 	      grub_dprintf ("multiboot_loader", "Error loading shdr %d\n", i);
-	      return err;
+	      grub_errno = err;
+	      goto fail;
 	    }
 	  src = get_virtual_current_address (ch);
 	  target = get_physical_target_address (ch);
 
 	  if (grub_file_seek (mld->file, sh->sh_offset) == (grub_off_t) -1)
-	    return grub_errno;
+	    goto fail;
 
           if (grub_file_read (mld->file, src, sh->sh_size)
               != (grub_ssize_t) sh->sh_size)
@@ -301,12 +302,16 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld)
 	      if (!grub_errno)
 		grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
 			    mld->filename);
-	      return grub_errno;
+	      goto fail;
 	    }
 	  sh->sh_addr = target;
 	}
       GRUB_MULTIBOOT (add_elfsyms) (shnum, ehdr->e_shentsize,
 				    shstrndx, shdr);
+      return GRUB_ERR_NONE;
+
+ fail:
+      grub_free (shdr);
     }
 
 #undef phdr
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH V2] multiboot: fix memory leak
  2022-11-10  7:01 [PATCH V2] multiboot: fix memory leak t.feng
@ 2022-11-14 15:41 ` Daniel Kiper
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Kiper @ 2022-11-14 15:41 UTC (permalink / raw)
  To: fengtao40; +Cc: grub-devel, yanan, zhaowei23

On Thu, Nov 10, 2022 at 03:01:15PM +0800, t.feng via Grub-devel wrote:
> The commit eb33e61b3 (multiboot: fix memory leak) did not fix all
> issues. Fix all of them right now.
>
> Fixes: eb33e61b3 (multiboot: fix memory leak)
>
> Signed-off-by: "t.feng" <fengtao40@huawei.com>

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>

Daniel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-14 23:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10  7:01 [PATCH V2] multiboot: fix memory leak t.feng
2022-11-14 15:41 ` Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.