qcow2: Free allocated L2 cluster on error
authorMax Reitz <mreitz@redhat.com>
Wed, 25 Sep 2013 14:37:19 +0000 (16:37 +0200)
committerStefan Hajnoczi <stefanha@redhat.com>
Mon, 7 Oct 2013 11:23:19 +0000 (13:23 +0200)
If an error occurs in l2_allocate, the allocated (but unused) L2 cluster
should be freed.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
block/qcow2-cluster.c

index 2ed45f0..0fd26bb 100644 (file)
@@ -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;
 }