提交 09d7eba9 编写于 作者: M Michal Privoznik

qemu: Fix memory leak on metadata fetching

As written in virStorageFileGetMetadataFromFD decription, caller
must free metadata after use. Qemu driver miss this and therefore
leak metadata which can grow to huge mem leak if somebody query
for blockInfo a lot.
上级 c6a4c375
...@@ -6949,7 +6949,7 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom, ...@@ -6949,7 +6949,7 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom,
int ret = -1; int ret = -1;
int fd = -1; int fd = -1;
off_t end; off_t end;
virStorageFileMetadata meta; virStorageFileMetadata *meta = NULL;
virDomainDiskDefPtr disk = NULL; virDomainDiskDefPtr disk = NULL;
struct stat sb; struct stat sb;
int i; int i;
...@@ -7017,9 +7017,14 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom, ...@@ -7017,9 +7017,14 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom,
} }
} }
if (VIR_ALLOC(meta) < 0) {
virReportOOMError();
goto cleanup;
}
if (virStorageFileGetMetadataFromFD(path, fd, if (virStorageFileGetMetadataFromFD(path, fd,
format, format,
&meta) < 0) meta) < 0)
goto cleanup; goto cleanup;
/* Get info for normal formats */ /* Get info for normal formats */
...@@ -7056,8 +7061,8 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom, ...@@ -7056,8 +7061,8 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom,
/* If the file we probed has a capacity set, then override /* If the file we probed has a capacity set, then override
* what we calculated from file/block extents */ * what we calculated from file/block extents */
if (meta.capacity) if (meta->capacity)
info->capacity = meta.capacity; info->capacity = meta->capacity;
/* Set default value .. */ /* Set default value .. */
info->allocation = info->physical; info->allocation = info->physical;
...@@ -7091,6 +7096,7 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom, ...@@ -7091,6 +7096,7 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom,
} }
cleanup: cleanup:
virStorageFileFreeMetadata(meta);
VIR_FORCE_CLOSE(fd); VIR_FORCE_CLOSE(fd);
if (vm) if (vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册