From: Sasha Levin <levinsasha928@gmail.com>
To: penberg@kernel.org
Cc: mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com,
kvm@vger.kernel.org, Sasha Levin <levinsasha928@gmail.com>
Subject: [PATCH 1/2 V2] kvm tools: Fix leak in QCOW
Date: Sat, 16 Apr 2011 14:45:43 +0300 [thread overview]
Message-ID: <1302954344-11700-1-git-send-email-levinsasha928@gmail.com> (raw)
Fixed leak when reading a zero sector, also simplified flow a bit.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/qcow.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/tools/kvm/qcow.c b/tools/kvm/qcow.c
index 9b9af86..ceac721 100644
--- a/tools/kvm/qcow.c
+++ b/tools/kvm/qcow.c
@@ -44,7 +44,7 @@ static int qcow1_read_sector(struct disk_image *self, uint64_t sector, void *dst
uint64_t l2_table_size;
uint64_t clust_offset;
uint64_t clust_start;
- uint64_t *l2_table;
+ uint64_t *l2_table = NULL;
uint64_t l1_idx;
uint64_t l2_idx;
uint64_t offset;
@@ -69,24 +69,24 @@ static int qcow1_read_sector(struct disk_image *self, uint64_t sector, void *dst
goto out_error;
if (pread_in_full(q->fd, l2_table, sizeof(uint64_t) * l2_table_size, l2_table_offset) < 0)
- goto out_error_free_l2;
+ goto out_error;
l2_idx = get_l2_index(q, offset);
if (l2_idx >= l2_table_size)
- goto out_error_free_l2;
+ goto out_error;
clust_start = be64_to_cpu(l2_table[l2_idx]);
+ free(l2_table);
+
if (!clust_start)
goto zero_sector;
clust_offset = get_cluster_offset(q, offset);
if (pread_in_full(q->fd, dst, dst_len, clust_start + clust_offset) < 0)
- goto out_error_free_l2;
-
- free(l2_table);
+ goto out_error;
return 0;
@@ -95,9 +95,9 @@ zero_sector:
return 0;
-out_error_free_l2:
- free(l2_table);
out_error:
+ free(l2_table);
+
return -1;
}
--
1.7.5.rc1
next reply other threads:[~2011-04-16 11:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-16 11:45 Sasha Levin [this message]
2011-04-16 11:45 ` [PATCH 2/2] kvm tools: Add scatter-gather support for disk images Sasha Levin
2011-04-16 13:55 ` Pekka Enberg
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=1302954344-11700-1-git-send-email-levinsasha928@gmail.com \
--to=levinsasha928@gmail.com \
--cc=asias.hejun@gmail.com \
--cc=gorcunov@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=penberg@kernel.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