kvm tools: Fix leak in QCOW

Fixed leak when reading a zero sector, also simplified flow a bit.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
Sasha Levin
2015-06-01 16:39:42 +01:00
committed by Will Deacon
parent ac60053316
commit b6edb0ec95
+8 -8
View File
@@ -44,7 +44,7 @@ static int qcow1_read_sector(struct disk_image *self, uint64_t sector, void *dst
uint64_t l2_table_size;
uint64_t clust_offset;
uint64_t clust_start;
uint64_t *l2_table;
uint64_t *l2_table = NULL;
uint64_t l1_idx;
uint64_t l2_idx;
uint64_t offset;
@@ -69,24 +69,24 @@ static int qcow1_read_sector(struct disk_image *self, uint64_t sector, void *dst
goto out_error;
if (pread_in_full(q->fd, l2_table, sizeof(uint64_t) * l2_table_size, l2_table_offset) < 0)
goto out_error_free_l2;
goto out_error;
l2_idx = get_l2_index(q, offset);
if (l2_idx >= l2_table_size)
goto out_error_free_l2;
goto out_error;
clust_start = be64_to_cpu(l2_table[l2_idx]);
free(l2_table);
if (!clust_start)
goto zero_sector;
clust_offset = get_cluster_offset(q, offset);
if (pread_in_full(q->fd, dst, dst_len, clust_start + clust_offset) < 0)
goto out_error_free_l2;
free(l2_table);
goto out_error;
return 0;
@@ -95,9 +95,9 @@ zero_sector:
return 0;
out_error_free_l2:
free(l2_table);
out_error:
free(l2_table);
return -1;
}