qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH] qcow2: Fix segfault when qcow2 preallocate fails


From: Stefan Hajnoczi
Subject: [Qemu-devel] [PATCH] qcow2: Fix segfault when qcow2 preallocate fails
Date: Tue, 26 Oct 2010 14:23:19 +0100

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 <address@hidden>
---
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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]