Blame 0042-rbd-avoid-qemu_rbd_snap_list-memory-leaks.patch

298366
From fc06b430942e84a2a69e2a80a6d5b376a8064020 Mon Sep 17 00:00:00 2001
298366
From: Stefan Hajnoczi <stefanha@redhat.com>
298366
Date: Wed, 25 Sep 2013 16:00:48 +0200
298366
Subject: [PATCH] rbd: avoid qemu_rbd_snap_list() memory leaks
298366
298366
When there are no snapshots qemu_rbd_snap_list() returns 0 and the
298366
snapshot table pointer is NULL.  Don't forget to free the snaps buffer
298366
we allocated for librbd rbd_snap_list().
298366
298366
When the function succeeds don't forget to free the snaps buffer after
298366
calling rbd_snap_list_end().
298366
298366
Cc: qemu-stable@nongnu.org
298366
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
298366
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
298366
(cherry picked from commit 9e6337d0818650362149b734d53edf9489f3acaa)
298366
298366
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
298366
---
298366
 block/rbd.c | 3 ++-
298366
 1 file changed, 2 insertions(+), 1 deletion(-)
298366
298366
diff --git a/block/rbd.c b/block/rbd.c
298366
index cb71751..7e7c735 100644
298366
--- a/block/rbd.c
298366
+++ b/block/rbd.c
298366
@@ -934,7 +934,7 @@ static int qemu_rbd_snap_list(BlockDriverState *bs,
298366
     do {
298366
         snaps = g_malloc(sizeof(*snaps) * max_snaps);
298366
         snap_count = rbd_snap_list(s->image, snaps, &max_snaps);
298366
-        if (snap_count < 0) {
298366
+        if (snap_count <= 0) {
298366
             g_free(snaps);
298366
         }
298366
     } while (snap_count == -ERANGE);
298366
@@ -958,6 +958,7 @@ static int qemu_rbd_snap_list(BlockDriverState *bs,
298366
         sn_info->vm_clock_nsec = 0;
298366
     }
298366
     rbd_snap_list_end(snaps);
298366
+    g_free(snaps);
298366
 
298366
  done:
298366
     *psn_tab = sn_tab;