From: Max Reitz Date: Wed, 25 Sep 2013 14:37:19 +0000 (+0200) Subject: qcow2: Free allocated L2 cluster on error X-Git-Tag: qemu-xen-4.5.0-rc1~433^2~2 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=e3b21ef9e016e6d91fd71e44af5e23fb359e18f9;p=qemu-upstream-4.6-testing.git qcow2: Free allocated L2 cluster on error If an error occurs in l2_allocate, the allocated (but unused) L2 cluster should be freed. Signed-off-by: Max Reitz Reviewed-by: Benoit Canet Signed-off-by: Stefan Hajnoczi --- diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 2ed45f068..0fd26bb4c 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -273,6 +273,10 @@ fail: qcow2_cache_put(bs, s->l2_table_cache, (void**) table); } s->l1_table[l1_index] = old_l2_offset; + if (l2_offset > 0) { + qcow2_free_clusters(bs, l2_offset, s->l2_size * sizeof(uint64_t), + QCOW2_DISCARD_ALWAYS); + } return ret; }