From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:37582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdFYa-0002q9-Tc for qemu-devel@nongnu.org; Fri, 17 May 2013 03:58:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UdFYV-0000ue-3j for qemu-devel@nongnu.org; Fri, 17 May 2013 03:58:28 -0400 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:49146) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdFYU-0000qu-G7 for qemu-devel@nongnu.org; Fri, 17 May 2013 03:58:23 -0400 Received: from /spool/local by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 17 May 2013 17:45:26 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id D00402BB0051 for ; Fri, 17 May 2013 17:58:13 +1000 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r4H7w6Hq22020224 for ; Fri, 17 May 2013 17:58:06 +1000 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r4H7wDIG000619 for ; Fri, 17 May 2013 17:58:13 +1000 From: Wenchao Xia Date: Fri, 17 May 2013 15:56:44 +0800 Message-Id: <1368777405-8750-2-git-send-email-xiawenc@linux.vnet.ibm.com> In-Reply-To: <1368777405-8750-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1368777405-8750-1-git-send-email-xiawenc@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH V2 1/2] qcow2: free allocated cluster on fail in qcow2_write_snapshots() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, Wenchao Xia , stefanha@gmail.com Signed-off-by: Wenchao Xia --- block/qcow2-snapshot.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 992a5c8..45da32d 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -180,13 +180,13 @@ static int qcow2_write_snapshots(BlockDriverState *bs) /* Allocate space for the new snapshot list */ snapshots_offset = qcow2_alloc_clusters(bs, snapshots_size); - offset = snapshots_offset; - if (offset < 0) { - return offset; + ret = offset = snapshots_offset; + if (ret < 0) { + goto fail; } ret = bdrv_flush(bs); if (ret < 0) { - return ret; + goto fail; } /* Write all snapshots to the new list */ @@ -268,6 +268,8 @@ static int qcow2_write_snapshots(BlockDriverState *bs) return 0; fail: + /* free the new snapshot table */ + qcow2_free_clusters(bs, snapshots_offset, snapshots_size); return ret; } -- 1.7.1