mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-04 20:15:19 +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__
|
||||
{
|
||||
int ret;
|
||||
char *sysfs_cpuinfo;
|
||||
int ret = -1;
|
||||
char *sysfs_cpuinfo = NULL;
|
||||
FILE *cpuinfo = fopen(CPUINFO_PATH, "r");
|
||||
if (!cpuinfo) {
|
||||
virReportSystemError(errno,
|
||||
@ -637,20 +637,19 @@ int nodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo) {
|
||||
|
||||
if (virAsprintf(&sysfs_cpuinfo, CPU_SYS_PATH) < 0) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = linuxNodeInfoCPUPopulate(cpuinfo, sysfs_cpuinfo, nodeinfo);
|
||||
VIR_FORCE_FCLOSE(cpuinfo);
|
||||
if (ret < 0) {
|
||||
VIR_FREE(sysfs_cpuinfo);
|
||||
return -1;
|
||||
}
|
||||
if (ret < 0)
|
||||
goto cleanup;
|
||||
|
||||
VIR_FREE(sysfs_cpuinfo);
|
||||
/* Convert to KB. */
|
||||
nodeinfo->memory = physmem_total () / 1024;
|
||||
|
||||
cleanup:
|
||||
VIR_FORCE_FCLOSE(cpuinfo);
|
||||
VIR_FREE(sysfs_cpuinfo);
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
|
Loading…
Reference in New Issue
Block a user