1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2025-02-12 20:24:05 +00:00

Fix handle leaks in rdmsr.c

All three leaks would occur in erroneous
function paths.
This commit is contained in:
Pavol Žáčik 2024-05-22 09:39:32 +02:00 committed by The Tumultuous Unicorn Of Darkness
parent 954d9d43ef
commit e66eee8c6b

View file

@ -96,6 +96,7 @@ struct msr_driver_t* cpu_msr_driver_open_core(unsigned core_num)
handle = (struct msr_driver_t*) malloc(sizeof(struct msr_driver_t));
if (!handle) {
cpuid_set_error(ERR_NO_MEM);
close(fd);
return NULL;
}
handle->fd = fd;
@ -1069,8 +1070,10 @@ int msr_serialize_raw_data(struct msr_driver_t* handle, const char* filename)
/* Get cached decoded CPUID information */
id = get_cached_cpuid();
if (id->vendor == VENDOR_UNKNOWN)
if (id->vendor == VENDOR_UNKNOWN) {
fclose(f);
return cpuid_get_error();
}
/* Get CPU stock speed */
if (cpu_clock == 0)
@ -1082,7 +1085,7 @@ int msr_serialize_raw_data(struct msr_driver_t* handle, const char* filename)
case VENDOR_HYGON:
case VENDOR_AMD: msr = amd_msr; break;
case VENDOR_INTEL: msr = intel_msr; break;
default: return cpuid_set_error(ERR_CPU_UNKN);
default: fclose(f); return cpuid_set_error(ERR_CPU_UNKN);
}
/* Print raw MSR values */