Skip to content

Commit

Permalink
qemu-img: eliminate memory leak
Browse files Browse the repository at this point in the history
Not particularly important since qemu-img exits immediately after
calling img_rebase, but easily fixed.  Coverity says thanks.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
bonzini authored and kevmw committed Mar 14, 2016
1 parent 0dcee62 commit 396374c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions qemu-img.c
Expand Up @@ -2775,6 +2775,8 @@ static int img_snapshot(int argc, char **argv)
static int img_rebase(int argc, char **argv)
{
BlockBackend *blk = NULL, *blk_old_backing = NULL, *blk_new_backing = NULL;
uint8_t *buf_old = NULL;
uint8_t *buf_new = NULL;
BlockDriverState *bs = NULL;
char *filename;
const char *fmt, *cache, *src_cache, *out_basefmt, *out_baseimg;
Expand Down Expand Up @@ -2957,8 +2959,6 @@ static int img_rebase(int argc, char **argv)
int64_t new_backing_num_sectors = 0;
uint64_t sector;
int n;
uint8_t * buf_old;
uint8_t * buf_new;
float local_progress = 0;

buf_old = blk_blockalign(blk, IO_BUF_SIZE);
Expand Down Expand Up @@ -3070,9 +3070,6 @@ static int img_rebase(int argc, char **argv)
}
qemu_progress_print(local_progress, 100);
}

qemu_vfree(buf_old);
qemu_vfree(buf_new);
}

/*
Expand Down Expand Up @@ -3108,6 +3105,8 @@ static int img_rebase(int argc, char **argv)
blk_unref(blk_old_backing);
blk_unref(blk_new_backing);
}
qemu_vfree(buf_old);
qemu_vfree(buf_new);

blk_unref(blk);
if (ret) {
Expand Down

0 comments on commit 396374c

Please sign in to comment.