From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VIrgP-0005Uz-JT for qemu-devel@nongnu.org; Sun, 08 Sep 2013 22:58:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VIrgC-0000iH-NR for qemu-devel@nongnu.org; Sun, 08 Sep 2013 22:58:33 -0400 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:47658) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VIrgC-0000hO-1P for qemu-devel@nongnu.org; Sun, 08 Sep 2013 22:58:20 -0400 Received: from /spool/local by e28smtp01.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 9 Sep 2013 08:18:44 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id E01B03940053 for ; Mon, 9 Sep 2013 08:27:59 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r893093V35782852 for ; Mon, 9 Sep 2013 08:30:10 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r892wADi007918 for ; Mon, 9 Sep 2013 08:28:11 +0530 From: Wenchao Xia Date: Mon, 9 Sep 2013 10:57:57 +0800 Message-Id: <1378695482-29805-3-git-send-email-xiawenc@linux.vnet.ibm.com> In-Reply-To: <1378695482-29805-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1378695482-29805-1-git-send-email-xiawenc@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH V3 2/7] 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, mreitz@redhat.com, Wenchao Xia , stefanha@gmail.com Signed-off-by: Wenchao Xia --- block/qcow2-snapshot.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 40393b2..9e2d695 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -186,7 +186,7 @@ static int qcow2_write_snapshots(BlockDriverState *bs) } ret = bdrv_flush(bs); if (ret < 0) { - return ret; + goto fail; } /* The snapshot list position has not yet been updated, so these clusters @@ -194,7 +194,7 @@ static int qcow2_write_snapshots(BlockDriverState *bs) ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_DEFAULT, offset, s->snapshots_size); if (ret < 0) { - return ret; + goto fail; } @@ -278,6 +278,9 @@ static int qcow2_write_snapshots(BlockDriverState *bs) return 0; fail: + /* free the new snapshot table */ + qcow2_free_clusters(bs, snapshots_offset, snapshots_size, + QCOW2_DISCARD_ALWAYS); return ret; } -- 1.7.1