Message ID | 1368777405-8750-2-git-send-email-xiawenc@linux.vnet.ibm.com |
---|---|
State | New |
Headers | show |
On Fri, May 17, 2013 at 03:56:44PM +0800, Wenchao Xia wrote: > Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com> > --- > 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().
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; }
Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com> --- block/qcow2-snapshot.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)