From: Dirk Behme <dirk.behme@googlemail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Fix memory leaks in ELF loader
Date: Mon, 01 May 2006 18:44:10 +0200 [thread overview]
Message-ID: <44563ADA.2040501@gmail.com> (raw)
[-- 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;
}
next reply other threads:[~2006-05-01 16:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-01 16:44 Dirk Behme [this message]
2006-05-01 18:10 ` [Qemu-devel] [PATCH] Fix memory leaks in ELF loader Fabrice Bellard
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=44563ADA.2040501@gmail.com \
--to=dirk.behme@googlemail.com \
--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).