[PATCH] qcow2: Fix segfault when qcow2 preallocate fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When an image is created with -o preallocate, ensure that we only call
preallocate() if the image was indeed opened successfully.  Also use
bdrv_delete() instead of bdrv_close() to avoid leaking the
BlockDriverState structure.

This fixes the segfault reported at
https://bugzilla.redhat.com/show_bug.cgi?id=646538.

Signed-off-by: Stefan Hajnoczi <stefanha@xxxxxxxxxxxxxxxxxx>
---
Here's a fix for the segfault.

 block/qcow2.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index ee3481b..0fceb0d 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1059,9 +1059,11 @@ exit:
         BlockDriverState *bs;
         BlockDriver *drv = bdrv_find_format("qcow2");
         bs = bdrv_new("");
-        bdrv_open(bs, filename, BDRV_O_CACHE_WB | BDRV_O_RDWR, drv);
-        ret = preallocate(bs);
-        bdrv_close(bs);
+        ret = bdrv_open(bs, filename, BDRV_O_CACHE_WB | BDRV_O_RDWR, drv);
+        if (ret == 0) {
+            ret = preallocate(bs);
+        }
+        bdrv_delete(bs);
     }
 
     return ret;
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux