qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Fix memory leaks in ELF loader
@ 2006-05-01 16:44 Dirk Behme
  2006-05-01 18:10 ` Fabrice Bellard
  0 siblings, 1 reply; 3+ messages in thread
From: Dirk Behme @ 2006-05-01 16:44 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 49 bytes --]


Fix memory leaks in ELF loader.

Regards

Dirk


[-- Attachment #2: qemu-elf-loader.txt --]
[-- Type: text/plain, Size: 1450 bytes --]

--- 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;
 }
 



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

* Re: [Qemu-devel] [PATCH] Fix memory leaks in ELF loader
  2006-05-01 16:44 [Qemu-devel] [PATCH] Fix memory leaks in ELF loader Dirk Behme
@ 2006-05-01 18:10 ` Fabrice Bellard
  2006-05-02 15:53   ` Dirk Behme
  0 siblings, 1 reply; 3+ messages in thread
From: Fabrice Bellard @ 2006-05-01 18:10 UTC (permalink / raw)
  To: qemu-devel

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

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

* Re: [Qemu-devel] [PATCH] Fix memory leaks in ELF loader
  2006-05-01 18:10 ` Fabrice Bellard
@ 2006-05-02 15:53   ` Dirk Behme
  0 siblings, 0 replies; 3+ messages in thread
From: Dirk Behme @ 2006-05-02 15:53 UTC (permalink / raw)
  To: qemu-devel

Fabrice Bellard wrote:
> Why adding several labels ? qemu_free(NULL) is perfectly valid. I would 
> just add the missing "qemu_free(phdr)" ...

Okay. Wasn't sure about this ;)

Do you want a patch for "qemu_free(phdr)"?

Dirk

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

end of thread, other threads:[~2006-05-02 15:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-01 16:44 [Qemu-devel] [PATCH] Fix memory leaks in ELF loader Dirk Behme
2006-05-01 18:10 ` Fabrice Bellard
2006-05-02 15:53   ` Dirk Behme

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).