From: Kevin Wolf Date: Wed, 1 Jun 2011 08:50:00 +0000 (+0200) Subject: qcow2: Fix memory leaks in error cases X-Git-Tag: TizenStudio_2.0_p2.3.2~208^2~5703 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=80fa3341a70151d250be92ae900e3c1580817540;p=sdk%2Femulator%2Fqemu.git qcow2: Fix memory leaks in error cases This fixes memory leaks that may be caused by I/O errors during L1 table growth (can happen during save_vm) and in qemu-img check. Signed-off-by: Kevin Wolf --- diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 750abe3..c9e7bbd 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -70,7 +70,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size, bool exact_size) ret = qcow2_cache_flush(bs, s->refcount_block_cache); if (ret < 0) { - return ret; + goto fail; } BLKDBG_EVENT(bs->file, BLKDBG_L1_GROW_WRITE_TABLE); diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index d62dc1c..ac95b88 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1086,7 +1086,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res) ret = check_refcounts_l1(bs, res, refcount_table, nb_clusters, s->l1_table_offset, s->l1_size, 1); if (ret < 0) { - return ret; + goto fail; } /* snapshots */ @@ -1095,7 +1095,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res) ret = check_refcounts_l1(bs, res, refcount_table, nb_clusters, sn->l1_table_offset, sn->l1_size, 0); if (ret < 0) { - return ret; + goto fail; } } inc_refcounts(bs, res, refcount_table, nb_clusters, @@ -1159,8 +1159,11 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res) } } + ret = 0; + +fail: qemu_free(refcount_table); - return 0; + return ret; }