mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-06 21:15:22 +00:00
Coverity: Fix resource leak in nodeinfo.c
Error: RESOURCE_LEAK:
/builddir/build/BUILD/libvirt-0.9.10/src/nodeinfo.c:629: alloc_fn: Calling allocation function "fopen".
/builddir/build/BUILD/libvirt-0.9.10/src/nodeinfo.c:629: var_assign: Assigning: "cpuinfo" = storage returned from "fopen("/proc/cpuinfo", "r")".
/builddir/build/BUILD/libvirt-0.9.10/src/nodeinfo.c:638: leaked_storage: Variable "cpuinfo" going out of scope leaks the storage it points to.
(cherry picked from commit 739cfc3161
)
This commit is contained in:
parent
656875281a
commit
707624b3d9
@ -626,8 +626,8 @@ int nodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo) {
|
|||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = -1;
|
||||||
char *sysfs_cpuinfo;
|
char *sysfs_cpuinfo = NULL;
|
||||||
FILE *cpuinfo = fopen(CPUINFO_PATH, "r");
|
FILE *cpuinfo = fopen(CPUINFO_PATH, "r");
|
||||||
if (!cpuinfo) {
|
if (!cpuinfo) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
@ -637,20 +637,19 @@ int nodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo) {
|
|||||||
|
|
||||||
if (virAsprintf(&sysfs_cpuinfo, CPU_SYS_PATH) < 0) {
|
if (virAsprintf(&sysfs_cpuinfo, CPU_SYS_PATH) < 0) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = linuxNodeInfoCPUPopulate(cpuinfo, sysfs_cpuinfo, nodeinfo);
|
ret = linuxNodeInfoCPUPopulate(cpuinfo, sysfs_cpuinfo, nodeinfo);
|
||||||
VIR_FORCE_FCLOSE(cpuinfo);
|
if (ret < 0)
|
||||||
if (ret < 0) {
|
goto cleanup;
|
||||||
VIR_FREE(sysfs_cpuinfo);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_FREE(sysfs_cpuinfo);
|
|
||||||
/* Convert to KB. */
|
/* Convert to KB. */
|
||||||
nodeinfo->memory = physmem_total () / 1024;
|
nodeinfo->memory = physmem_total () / 1024;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
VIR_FORCE_FCLOSE(cpuinfo);
|
||||||
|
VIR_FREE(sysfs_cpuinfo);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user