#ifdef __linux__
{
- int ret;
- char *sysfs_cpuinfo;
+ int ret = -1;
+ char *sysfs_cpuinfo = NULL;
FILE *cpuinfo = fopen(CPUINFO_PATH, "r");
if (!cpuinfo) {
virReportSystemError(errno,
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