qcow2: Handle QCowL2Meta on error in preallocate_co()
commit1a52b73dbad8f0b72ba1df30a817926983037565
authorAlberto Garcia <berto@igalia.com>
Tue, 8 Sep 2020 14:08:27 +0000 (8 16:08 +0200)
committerMax Reitz <mreitz@redhat.com>
Tue, 15 Sep 2020 09:05:13 +0000 (15 11:05 +0200)
tree4815f6896803374efcff8807fdf211cdafce277e
parent83a6a90009401f02bdb18fd2414dbae090d0f2b5
qcow2: Handle QCowL2Meta on error in preallocate_co()

If qcow2_alloc_cluster_offset() or qcow2_alloc_cluster_link_l2() fail
then this function simply returns the error code, potentially leaking
the QCowL2Meta structure and leaving stale items in s->cluster_allocs.

A second problem is that this function calls qcow2_free_any_clusters()
on failure but passing a host cluster offset instead of an L2 entry.
Luckily for normal uncompressed clusters a raw offset also works like
a valid L2 entry so it works just the same, but we should be using
qcow2_free_clusters() instead.

This patch fixes both problems by using qcow2_handle_l2meta().

Signed-off-by: Alberto Garcia <berto@igalia.com>
Message-Id: <cd3a6b9abd43f9c0b60be413d760f0cacc67eb66.1599573989.git.berto@igalia.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
block/qcow2.c