qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fabrice Bellard <fabrice@bellard.org>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] Fix memory leaks in ELF loader
Date: Mon, 01 May 2006 20:10:01 +0200	[thread overview]
Message-ID: <44564EF9.4060104@bellard.org> (raw)
In-Reply-To: <44563ADA.2040501@gmail.com>

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

  reply	other threads:[~2006-05-01 18:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-01 16:44 [Qemu-devel] [PATCH] Fix memory leaks in ELF loader Dirk Behme
2006-05-01 18:10 ` Fabrice Bellard [this message]
2006-05-02 15:53   ` Dirk Behme

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44564EF9.4060104@bellard.org \
    --to=fabrice@bellard.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).