Skip to contentSkip to conversation

rbd: avoid qemu_rbd_snap_list() memory leaks

PATCH In review Stefan Hajnoczi 2 participants 2 messages Sep 25, 2013 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rbd: avoid qemu_rbd_snap_list() memory leaks

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().

---
 block/rbd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
block/rbd.c +2 -1
index 11086c3..6c65b21 100644
@@ -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;
Signature · 1 line
1.8.3.1
#1 lore raw

Am 25.09.2013 um 16:00 hat Stefan Hajnoczi geschrieben:

Quoted 9 lines

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().

Thanks, updated the block branch with this.

Kevin