From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=51102 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PAjV1-0005j7-CX for qemu-devel@nongnu.org; Tue, 26 Oct 2010 09:23:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PAjUs-00078L-Mc for qemu-devel@nongnu.org; Tue, 26 Oct 2010 09:23:34 -0400 Received: from mtagate7.uk.ibm.com ([194.196.100.167]:60513) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PAjUs-00077K-Cn for qemu-devel@nongnu.org; Tue, 26 Oct 2010 09:23:26 -0400 Received: from d06nrmr1707.portsmouth.uk.ibm.com (d06nrmr1707.portsmouth.uk.ibm.com [9.149.39.225]) by mtagate7.uk.ibm.com (8.13.1/8.13.1) with ESMTP id o9QDNMvZ023046 for ; Tue, 26 Oct 2010 13:23:22 GMT Received: from d06av07.portsmouth.uk.ibm.com (d06av07.portsmouth.uk.ibm.com [9.149.37.248]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o9QDNMso2883782 for ; Tue, 26 Oct 2010 14:23:22 +0100 Received: from d06av07.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o9QDNMlx021046 for ; Tue, 26 Oct 2010 07:23:22 -0600 From: Stefan Hajnoczi Date: Tue, 26 Oct 2010 14:23:19 +0100 Message-Id: <1288099399-10010-1-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <4CC6D1EA.7050706@redhat.com> References: <4CC6D1EA.7050706@redhat.com> Subject: [Qemu-devel] [PATCH] qcow2: Fix segfault when qcow2 preallocate fails List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: Kevin Wolf , Anthony Liguori , Stefan Hajnoczi , kvm@vger.kernel.org, Juan Quintela , qemu-devel@nongnu.org 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 --- 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