Patchwork [3/7] img_convert(): Only try to free bs[] entries if bs is valid.

login
register
mail settings
Submitter Jes Sorensen
Date Dec. 6, 2010, 2:25 p.m.
Message ID <1291645540-9784-4-git-send-email-Jes.Sorensen@redhat.com>
Download mbox | patch
Permalink /patch/74371/
State New
Headers show

Comments

Jes Sorensen - Dec. 6, 2010, 2:25 p.m.
From: Jes Sorensen <Jes.Sorensen@redhat.com>

This allows for jumping to 'out:' consistently for error exit.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
 qemu-img.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
Stefan Hajnoczi - Dec. 6, 2010, 2:44 p.m.
On Mon, Dec 06, 2010 at 03:25:36PM +0100, Jes.Sorensen@redhat.com wrote:
> From: Jes Sorensen <Jes.Sorensen@redhat.com>
> 
> This allows for jumping to 'out:' consistently for error exit.
> 
> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
> ---
>  qemu-img.c |   13 ++++++++-----
>  1 files changed, 8 insertions(+), 5 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

Patch

diff --git a/qemu-img.c b/qemu-img.c
index eca99c4..aded72d 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -696,7 +696,8 @@  static int img_convert(int argc, char **argv)
 
     if (bs_n > 1 && out_baseimg) {
         error("-B makes no sense when concatenating multiple input images");
-        return 1;
+        ret = -1;
+        goto out;
     }
         
     bs = qemu_mallocz(bs_n * sizeof(BlockDriverState *));
@@ -974,12 +975,14 @@  out:
     if (out_bs) {
         bdrv_delete(out_bs);
     }
-    for (bs_i = 0; bs_i < bs_n; bs_i++) {
-        if (bs[bs_i]) {
-            bdrv_delete(bs[bs_i]);
+    if (bs) {
+        for (bs_i = 0; bs_i < bs_n; bs_i++) {
+            if (bs[bs_i]) {
+                bdrv_delete(bs[bs_i]);
+            }
         }
+        qemu_free(bs);
     }
-    qemu_free(bs);
     if (ret) {
         return 1;
     }