diff mbox

qcow2: Fix segfault when qcow2 preallocate fails

Message ID 1288099399-10010-1-git-send-email-stefanha@linux.vnet.ibm.com
State New
Headers show

Commit Message

Stefan Hajnoczi Oct. 26, 2010, 1:23 p.m. UTC
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@linux.vnet.ibm.com>
---
Here's a fix for the segfault.

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

Comments

Kevin Wolf Oct. 26, 2010, 1:48 p.m. UTC | #1
Am 26.10.2010 15:23, schrieb Stefan Hajnoczi:
> 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@linux.vnet.ibm.com>

Looks good for stable-0.13. In master we'll have the new qcow_create2
implementation as soon as Anthony pulls, so it doesn't apply there.

Kevin
Stefan Hajnoczi Oct. 26, 2010, 2:04 p.m. UTC | #2
On Tue, Oct 26, 2010 at 2:48 PM, Kevin Wolf <kwolf@redhat.com> wrote:
> Am 26.10.2010 15:23, schrieb Stefan Hajnoczi:
>> 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@linux.vnet.ibm.com>
>
> Looks good for stable-0.13. In master we'll have the new qcow_create2
> implementation as soon as Anthony pulls, so it doesn't apply there.

I forgot about that :).  Thanks Kevin.

Stefan
diff mbox

Patch

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;