From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FacrL-0000pL-Et for qemu-devel@nongnu.org; Mon, 01 May 2006 14:10:59 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FacrI-0000ou-Vl for qemu-devel@nongnu.org; Mon, 01 May 2006 14:10:58 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FacrI-0000or-QY for qemu-devel@nongnu.org; Mon, 01 May 2006 14:10:56 -0400 Received: from [84.96.92.61] (helo=sMtp.neuf.fr) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FacvA-0005WS-DH for qemu-devel@nongnu.org; Mon, 01 May 2006 14:14:56 -0400 Received: from [84.102.211.147] by sp604002mt.gpm.neuf.ld (Sun Java System Messaging Server 6.2-5.05 (built Feb 16 2006)) with ESMTP id <0IYL00073MHX9B80@sp604002mt.gpm.neuf.ld> for qemu-devel@nongnu.org; Mon, 01 May 2006 20:10:45 +0200 (CEST) Date: Mon, 01 May 2006 20:10:01 +0200 From: Fabrice Bellard Subject: Re: [Qemu-devel] [PATCH] Fix memory leaks in ELF loader In-reply-to: <44563ADA.2040501@gmail.com> Message-id: <44564EF9.4060104@bellard.org> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-transfer-encoding: 7BIT References: <44563ADA.2040501@gmail.com> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Why adding several labels ? qemu_free(NULL) is perfectly valid. I would just add the missing "qemu_free(phdr)" ... Fabrice. Dirk Behme wrote: > > Fix memory leaks in ELF loader. > > Regards > > Dirk > > > ------------------------------------------------------------------------ > > --- elf_ops.h_orig 2006-05-01 09:01:47.000000000 +0200 > +++ elf_ops.h 2006-05-01 09:09:34.000000000 +0200 > @@ -148,7 +148,7 @@ int glue(load_elf, SZ)(int fd, int64_t v > uint8_t *data = NULL; > > if (read(fd, &ehdr, sizeof(ehdr)) != sizeof(ehdr)) > - goto fail; > + goto fail1; > if (must_swab) { > glue(bswap_ehdr, SZ)(&ehdr); > } > @@ -162,9 +162,9 @@ int glue(load_elf, SZ)(int fd, int64_t v > lseek(fd, ehdr.e_phoff, SEEK_SET); > phdr = qemu_mallocz(size); > if (!phdr) > - goto fail; > + goto fail2; > if (read(fd, phdr, size) != size) > - goto fail; > + goto fail2; > if (must_swab) { > for(i = 0; i < ehdr.e_phnum; i++) { > ph = &phdr[i]; > @@ -181,9 +181,9 @@ int glue(load_elf, SZ)(int fd, int64_t v > data = qemu_mallocz(mem_size); > if (ph->p_filesz > 0) { > if (lseek(fd, ph->p_offset, SEEK_SET) < 0) > - goto fail; > + goto fail3; > if (read(fd, data, ph->p_filesz) != ph->p_filesz) > - goto fail; > + goto fail3; > } > addr = ph->p_vaddr + virt_to_phys_addend; > > @@ -195,10 +195,13 @@ int glue(load_elf, SZ)(int fd, int64_t v > data = NULL; > } > } > + qemu_free(phdr); > return total_size; > - fail: > + fail3: > qemu_free(data); > + fail2: > qemu_free(phdr); > + fail1: > return -1; > } > > > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Qemu-devel mailing list > Qemu-devel@nongnu.org > http://lists.nongnu.org/mailman/listinfo/qemu-devel