From patchwork Tue Oct 26 13:23:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 69250 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BF7FCB70D5 for ; Wed, 27 Oct 2010 00:47:38 +1100 (EST) Received: from localhost ([127.0.0.1]:57892 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PAjsF-00053b-KW for incoming@patchwork.ozlabs.org; Tue, 26 Oct 2010 09:47:35 -0400 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 Received: from stefan-thinkpad.manchester-maybrook.uk.ibm.com (dyn-9-174-219-27.manchester-maybrook.uk.ibm.com [9.174.219.27]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o9QDNLF3021043; Tue, 26 Oct 2010 07:23:21 -0600 From: Stefan Hajnoczi To: Avi Kivity Date: Tue, 26 Oct 2010 14:23:19 +0100 Message-Id: <1288099399-10010-1-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <4CC6D1EA.7050706@redhat.com> References: <4CC6D1EA.7050706@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Kevin Wolf , Anthony Liguori , Stefan Hajnoczi , kvm@vger.kernel.org, Juan Quintela , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] qcow2: Fix segfault when qcow2 preallocate fails X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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;