* [Qemu-devel] [PATCH v2] rbd: avoid qemu_rbd_snap_list() memory leaks
@ 2013-09-25 14:00 Stefan Hajnoczi
2013-09-25 14:23 ` Kevin Wolf
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Hajnoczi @ 2013-09-25 14:00 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Michael Roth, Stefan Hajnoczi, qemu-stable
When there are no snapshots qemu_rbd_snap_list() returns 0 and the
snapshot table pointer is NULL. Don't forget to free the snaps buffer
we allocated for librbd rbd_snap_list().
When the function succeeds don't forget to free the snaps buffer after
calling rbd_snap_list_end().
Cc: qemu-stable@nongnu.org
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
block/rbd.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/block/rbd.c b/block/rbd.c
index 11086c3..6c65b21 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -943,7 +943,7 @@ static int qemu_rbd_snap_list(BlockDriverState *bs,
do {
snaps = g_malloc(sizeof(*snaps) * max_snaps);
snap_count = rbd_snap_list(s->image, snaps, &max_snaps);
- if (snap_count < 0) {
+ if (snap_count <= 0) {
g_free(snaps);
}
} while (snap_count == -ERANGE);
@@ -967,6 +967,7 @@ static int qemu_rbd_snap_list(BlockDriverState *bs,
sn_info->vm_clock_nsec = 0;
}
rbd_snap_list_end(snaps);
+ g_free(snaps);
done:
*psn_tab = sn_tab;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-09-25 14:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-25 14:00 [Qemu-devel] [PATCH v2] rbd: avoid qemu_rbd_snap_list() memory leaks Stefan Hajnoczi
2013-09-25 14:23 ` Kevin Wolf
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).