qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: Avi Kivity <avi@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
	kvm@vger.kernel.org, Juan Quintela <quintela@redhat.com>,
	qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] qcow2: Fix segfault when qcow2 preallocate fails
Date: Tue, 26 Oct 2010 14:23:19 +0100	[thread overview]
Message-ID: <1288099399-10010-1-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <4CC6D1EA.7050706@redhat.com>

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(-)

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

  parent reply	other threads:[~2010-10-26 13:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-25 19:51 [Qemu-devel] KVM call agenda for Oct 26 Juan Quintela
2010-10-25 19:53 ` [Qemu-devel] " Chris Wright
2010-10-26  8:20 ` Avi Kivity
2010-10-26 12:49   ` Anthony Liguori
2010-10-26 13:04     ` Avi Kivity
2010-10-26 13:22       ` Anthony Liguori
2010-10-26 13:24         ` Gleb Natapov
2010-10-26 13:23       ` Stefan Hajnoczi [this message]
2010-10-26 13:48         ` [Qemu-devel] Re: [PATCH] qcow2: Fix segfault when qcow2 preallocate fails Kevin Wolf
2010-10-26 14:04           ` Stefan Hajnoczi
2010-10-26 13:09 ` [Qemu-devel] Re: KVM call agenda for Oct 26 Gleb Natapov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1288099399-10010-1-git-send-email-stefanha@linux.vnet.ibm.com \
    --to=stefanha@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).