Received: from list by lists.gnu.org with archive (Exim 4.71) id 1aXlnT-0003pJ-5s for mharc-grub-devel@gnu.org; Mon, 22 Feb 2016 03:24:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXlnR-0003o9-2K for grub-devel@gnu.org; Mon, 22 Feb 2016 03:24:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aXlnN-0003x5-Rz for grub-devel@gnu.org; Mon, 22 Feb 2016 03:24:45 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:20331) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXlnN-0003wt-LE for grub-devel@gnu.org; Mon, 22 Feb 2016 03:24:41 -0500 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u1M8Ocii001750 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 22 Feb 2016 08:24:39 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u1M8Obtw015490 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 22 Feb 2016 08:24:37 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u1M8Oasl028453; Mon, 22 Feb 2016 08:24:37 GMT Received: from olila.local.net-space.pl (/10.175.203.154) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 22 Feb 2016 00:24:36 -0800 Date: Mon, 22 Feb 2016 09:24:32 +0100 From: Daniel Kiper To: Juergen Gross Subject: Re: [PATCH v4 02/11] xen: avoid memleaks on error Message-ID: <20160222082432.GM3482@olila.local.net-space.pl> References: <1456120999-5639-1-git-send-email-jgross@suse.com> <1456120999-5639-3-git-send-email-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1456120999-5639-3-git-send-email-jgross@suse.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: userv0021.oracle.com [156.151.31.71] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 141.146.126.69 Cc: grub-devel@gnu.org, phcoder@gmail.com, mchang@suse.com, xen-devel@lists.xen.org X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Feb 2016 08:24:46 -0000 On Mon, Feb 22, 2016 at 07:03:10AM +0100, Juergen Gross wrote: > When loading a Xen pv-kernel avoid memory leaks in case of errors. > > Signed-off-by: Juergen Gross > --- > grub-core/loader/i386/xen.c | 2 +- > grub-core/loader/i386/xen_fileXX.c | 17 +++++++++++------ > 2 files changed, 12 insertions(+), 7 deletions(-) > > diff --git a/grub-core/loader/i386/xen.c b/grub-core/loader/i386/xen.c > index 179e89c..f45f70f 100644 > --- a/grub-core/loader/i386/xen.c > +++ b/grub-core/loader/i386/xen.c > @@ -563,7 +563,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), > { > err = grub_relocator_alloc_chunk_addr (relocator, &ch, max_addr, size); > if (err) > - return err; > + goto fail; > > if (grub_initrd_load (&initrd_ctx, argv, > get_virtual_current_address (ch))) > diff --git a/grub-core/loader/i386/xen_fileXX.c b/grub-core/loader/i386/xen_fileXX.c > index 1ba5649..5475819 100644 > --- a/grub-core/loader/i386/xen_fileXX.c > +++ b/grub-core/loader/i386/xen_fileXX.c > @@ -35,7 +35,8 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, > if (grub_file_read (elf->file, buf, sz) != (grub_ssize_t) sz) > { > if (grub_errno) > - return grub_errno; > + goto out; > + grub_free (buf); > return grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), > elf->file->name); > } > @@ -123,14 +124,14 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, > { > xi->virt_base = grub_strtoull (ptr + sizeof ("VIRT_BASE=") - 1, &ptr, 16); > if (grub_errno) > - return grub_errno; > + goto out; > continue; > } > if (grub_strncmp (ptr, "VIRT_ENTRY=", sizeof ("VIRT_ENTRY=") - 1) == 0) > { > xi->entry_point = grub_strtoull (ptr + sizeof ("VIRT_ENTRY=") - 1, &ptr, 16); > if (grub_errno) > - return grub_errno; > + goto out; > continue; > } > if (grub_strncmp (ptr, "HYPERCALL_PAGE=", sizeof ("HYPERCALL_PAGE=") - 1) == 0) > @@ -138,7 +139,7 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, > xi->hypercall_page = grub_strtoull (ptr + sizeof ("HYPERCALL_PAGE=") - 1, &ptr, 16); > xi->has_hypercall_page = 1; > if (grub_errno) > - return grub_errno; > + goto out; > continue; > } > if (grub_strncmp (ptr, "ELF_PADDR_OFFSET=", sizeof ("ELF_PADDR_OFFSET=") - 1) == 0) > @@ -146,7 +147,7 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, > xi->paddr_offset = grub_strtoull (ptr + sizeof ("ELF_PADDR_OFFSET=") - 1, &ptr, 16); > has_paddr = 1; > if (grub_errno) > - return grub_errno; > + goto out; > continue; > } > } > @@ -154,7 +155,11 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, > xi->hypercall_page = (xi->hypercall_page << 12) + xi->virt_base; > if (!has_paddr) > xi->paddr_offset = xi->virt_base; > - return GRUB_ERR_NONE; > + > +out: > + grub_free (buf); > + > + return grub_errno; Are you sure that grub_errno is always set to GRUB_ERR_NONE if any GRUB2 function finished successfully? Maybe you should set initialize grub_errno with GRUB_ERR_NONE at the beginning of parse_xen_guest()? Daniel