Skip to content

Commit

Permalink
qemu-img: always goto out in img_snapshot() error paths
Browse files Browse the repository at this point in the history
The out label has the qemu_progress_end() and other cleanup calls.
Always goto out in error paths so the cleanup happens.  These error
paths now return 1 instead of -1.

Note that bdrv_unref(NULL) is safe.  We just need to initialize bs to
NULL at the top of the function.

We can now remove the obsolete bs_old_backing = NULL and bs_new_backing
= NULL for safe mode.  Originally it was necessary in commit 3e85c6f
("qemu-img rebase") but became useless in commit c2abcce ("qemu-img:
avoid calling exit(1) to release resources properly") because the
variables are already initialized during declaration.

Reported-by: John Snow <jsnow@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
  • Loading branch information
stefanhaRH committed Aug 29, 2014
1 parent cbda016 commit 40ed35a
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions qemu-img.c
Expand Up @@ -2304,7 +2304,7 @@ static int img_snapshot(int argc, char **argv)

static int img_rebase(int argc, char **argv)
{
BlockDriverState *bs, *bs_old_backing = NULL, *bs_new_backing = NULL;
BlockDriverState *bs = NULL, *bs_old_backing = NULL, *bs_new_backing = NULL;
BlockDriver *old_backing_drv, *new_backing_drv;
char *filename;
const char *fmt, *cache, *src_cache, *out_basefmt, *out_baseimg;
Expand Down Expand Up @@ -2376,14 +2376,14 @@ static int img_rebase(int argc, char **argv)
ret = bdrv_parse_cache_flags(cache, &flags);
if (ret < 0) {
error_report("Invalid cache option: %s", cache);
return -1;
goto out;
}

src_flags = BDRV_O_FLAGS;
ret = bdrv_parse_cache_flags(src_cache, &src_flags);
if (ret < 0) {
error_report("Invalid source cache option: %s", src_cache);
return -1;
goto out;
}

/*
Expand All @@ -2394,7 +2394,8 @@ static int img_rebase(int argc, char **argv)
*/
bs = bdrv_new_open("image", filename, fmt, flags, true, quiet);
if (!bs) {
return 1;
ret = -1;
goto out;
}

/* Find the right drivers for the backing files */
Expand All @@ -2420,11 +2421,7 @@ static int img_rebase(int argc, char **argv)
}

/* For safe rebasing we need to compare old and new backing file */
if (unsafe) {
/* Make the compiler happy */
bs_old_backing = NULL;
bs_new_backing = NULL;
} else {
if (!unsafe) {
char backing_name[1024];

bs_old_backing = bdrv_new("old_backing", &error_abort);
Expand Down

0 comments on commit 40ed35a

Please sign in to comment.