* [Qemu-devel] [PATCH] Fix a few memory leaks from early returns
@ 2010-07-20 19:04 Joel Schopp
0 siblings, 0 replies; only message in thread
From: Joel Schopp @ 2010-07-20 19:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Joel Schopp
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2010-07-20 19:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-20 19:04 [Qemu-devel] [PATCH] Fix a few memory leaks from early returns Joel Schopp
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).