img_convert(): Only try to free bs[] entries if bs is valid.
authorJes Sorensen <Jes.Sorensen@redhat.com>
Mon, 6 Dec 2010 14:25:36 +0000 (15:25 +0100)
committerKevin Wolf <kwolf@redhat.com>
Tue, 14 Dec 2010 14:44:21 +0000 (15:44 +0100)
This allows for jumping to 'out:' consistently for error exit.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qemu-img.c

index eca99c4a5d972c50ff297c01d6859239c04b3526..aded72d49fa79730126562dd28f9a8bb2353dda5 100644 (file)
@@ -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;
     }