提交 b3c0bfb6 编写于 作者: F Fam Zheng 提交者: Kevin Wolf

VMDK: fix leak of extent_file

Release extent_file on error in vmdk_parse_extents. Added closing files
in freeing extents.
Signed-off-by: NFam Zheng <famcool@gmail.com>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 7285477a
...@@ -179,11 +179,16 @@ static void vmdk_free_extents(BlockDriverState *bs) ...@@ -179,11 +179,16 @@ static void vmdk_free_extents(BlockDriverState *bs)
{ {
int i; int i;
BDRVVmdkState *s = bs->opaque; BDRVVmdkState *s = bs->opaque;
VmdkExtent *e;
for (i = 0; i < s->num_extents; i++) { for (i = 0; i < s->num_extents; i++) {
g_free(s->extents[i].l1_table); e = &s->extents[i];
g_free(s->extents[i].l2_cache); g_free(e->l1_table);
g_free(s->extents[i].l1_backup_table); g_free(e->l2_cache);
g_free(e->l1_backup_table);
if (e->file != bs->file) {
bdrv_delete(e->file);
}
} }
g_free(s->extents); g_free(s->extents);
} }
...@@ -619,12 +624,13 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, ...@@ -619,12 +624,13 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags,
s->desc_offset = 0; s->desc_offset = 0;
ret = vmdk_parse_extents(buf, bs, bs->file->filename); ret = vmdk_parse_extents(buf, bs, bs->file->filename);
if (ret) { if (ret) {
vmdk_free_extents(bs);
return ret; return ret;
} }
/* try to open parent images, if exist */ /* try to open parent images, if exist */
if (vmdk_parent_open(bs)) { if (vmdk_parent_open(bs)) {
g_free(s->extents); vmdk_free_extents(bs);
return -EINVAL; return -EINVAL;
} }
s->parent_cid = vmdk_read_cid(bs, 1); s->parent_cid = vmdk_read_cid(bs, 1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册