]> git.proxmox.com Git - qemu.git/commitdiff
rbd: avoid qemu_rbd_snap_list() memory leaks
authorStefan Hajnoczi <stefanha@redhat.com>
Wed, 25 Sep 2013 14:00:48 +0000 (16:00 +0200)
committerKevin Wolf <kwolf@redhat.com>
Wed, 25 Sep 2013 14:22:00 +0000 (16:22 +0200)
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>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/rbd.c

index f6d32371796f8c7e2636421b51d1a830747c5006..4a1ea5b5cead679249194ff17ec8d124cc1bea66 100644 (file)
@@ -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;