Skip to content

Commit

Permalink
rbd: avoid qemu_rbd_snap_list() memory leaks
Browse files Browse the repository at this point in the history
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: [email protected]
Signed-off-by: Stefan Hajnoczi <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
stefanhaRH authored and kevmw committed Sep 25, 2013
1 parent 5726d87 commit 9e6337d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion block/rbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 9e6337d

Please sign in to comment.