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: 282442 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9QDOBlX025074 for ; Tue, 26 Oct 2010 13:24:11 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933235Ab0JZNX2 (ORCPT ); Tue, 26 Oct 2010 09:23:28 -0400 Received: from mtagate3.uk.ibm.com ([194.196.100.163]:51807 "EHLO mtagate3.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932464Ab0JZNX1 (ORCPT ); Tue, 26 Oct 2010 09:23:27 -0400 Received: from d06nrmr1307.portsmouth.uk.ibm.com (d06nrmr1307.portsmouth.uk.ibm.com [9.149.38.129]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id o9QDNN28001488 for ; Tue, 26 Oct 2010 13:23:23 GMT Received: from d06av07.portsmouth.uk.ibm.com (d06av07.portsmouth.uk.ibm.com [9.149.37.248]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o9QDNMrR3559636 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 o9QDNMm5021046 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 Cc: , Anthony Liguori , Juan Quintela , , Kevin Wolf , Stefan Hajnoczi Subject: [PATCH] qcow2: Fix segfault when qcow2 preallocate fails 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 26 Oct 2010 13:24:11 +0000 (UTC) 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;