From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:60481) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdGoy-00025P-5R for qemu-devel@nongnu.org; Fri, 17 May 2013 05:19:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UdGot-0004ID-N9 for qemu-devel@nongnu.org; Fri, 17 May 2013 05:19:28 -0400 Received: from mail-bk0-x22d.google.com ([2a00:1450:4008:c01::22d]:64784) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdGot-0004I7-Gt for qemu-devel@nongnu.org; Fri, 17 May 2013 05:19:23 -0400 Received: by mail-bk0-f45.google.com with SMTP id je9so2217368bkc.32 for ; Fri, 17 May 2013 02:19:22 -0700 (PDT) Date: Fri, 17 May 2013 11:19:20 +0200 From: Stefan Hajnoczi Message-ID: <20130517091920.GB15001@stefanha-thinkpad.redhat.com> References: <1368777405-8750-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1368777405-8750-2-git-send-email-xiawenc@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1368777405-8750-2-git-send-email-xiawenc@linux.vnet.ibm.com> Subject: Re: [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: Wenchao Xia Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org On Fri, May 17, 2013 at 03:56:44PM +0800, Wenchao Xia wrote: > 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; > } If qcow2_alloc_clusters() failed then we must not call qcow2_free_clusters().