From: Joel Schopp <jschopp@austin.ibm.com>
To: qemu-devel@nongnu.org
Cc: Joel Schopp <jschopp@austin.ibm.com>
Subject: [Qemu-devel] [PATCH] Fix a few memory leaks from early returns
Date: Tue, 20 Jul 2010 14:04:17 -0500 [thread overview]
Message-ID: <1279652657-6466-1-git-send-email-jschopp@austin.ibm.com> (raw)
This is a simple cleanup patch that catches a few places where a function returns early but doesn't free recently malloced memory, resulting in a memory leak.
Signed-off-by: Joel Schopp <jschopp@austin.ibm.com>
---
linux-user/elfload.c | 8 ++++++--
qemu-io.c | 8 ++++++--
qemu-sockets.c | 1 +
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index accb44d..916b733 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1408,12 +1408,16 @@ static void load_symbols(struct elfhdr *hdr, int fd)
if (!syms)
return;
s->disas_strtab = strings = malloc(strtab.sh_size);
- if (!s->disas_strtab)
+ if (!s->disas_strtab) {
+ free(syms);
return;
+ }
lseek(fd, symtab.sh_offset, SEEK_SET);
- if (read(fd, syms, symtab.sh_size) != symtab.sh_size)
+ if (read(fd, syms, symtab.sh_size) != symtab.sh_size) {
+ free(syms);
return;
+ }
nsyms = symtab.sh_size / sizeof(struct elf_sym);
diff --git a/qemu-io.c b/qemu-io.c
index 7c6120b..9adda4c 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -1131,8 +1131,10 @@ aio_read_f(int argc, char **argv)
case 'P':
ctx->Pflag = 1;
ctx->pattern = parse_pattern(optarg);
- if (ctx->pattern < 0)
+ if (ctx->pattern < 0) {
+ free(ctx);
return 0;
+ }
break;
case 'q':
ctx->qflag = 1;
@@ -1232,8 +1234,10 @@ aio_write_f(int argc, char **argv)
break;
case 'P':
pattern = parse_pattern(optarg);
- if (pattern < 0)
+ if (pattern < 0) {
+ free(ctx);
return 0;
+ }
break;
default:
free(ctx);
diff --git a/qemu-sockets.c b/qemu-sockets.c
index c526324..4d2bd3c 100644
--- a/qemu-sockets.c
+++ b/qemu-sockets.c
@@ -344,6 +344,7 @@ int inet_dgram_opts(QemuOpts *opts)
if (0 != (rc = getaddrinfo(addr, port, &ai, &local))) {
fprintf(stderr,"getaddrinfo(%s,%s): %s\n", addr, port,
gai_strerror(rc));
+ freeaddrinfo(peer);
return -1;
}
if (sockets_debug) {
--
1.7.0.4
reply other threads:[~2010-07-20 19:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1279652657-6466-1-git-send-email-jschopp@austin.ibm.com \
--to=jschopp@austin.ibm.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).