From 558b8eb093beb14aaaa910cc5a444c11327bc33a Mon Sep 17 00:00:00 2001 From: Witold Baryluk Date: Sat, 28 Nov 2020 23:24:35 +0000 Subject: [PATCH] Properly initialize file pointers to null If in `init_cpu_power_data_k10temp` we fail to initialize all paths, and fail initialization, then in the destructor, we will most likely pass invalid value to the `fclose`. --- src/cpu.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cpu.h b/src/cpu.h index 53943acf..f4b3b2a0 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -68,10 +68,10 @@ struct CPUPowerData_k10temp : public CPUPowerData { fclose(this->socCurrentFile); }; - FILE* coreVoltageFile; - FILE* coreCurrentFile; - FILE* socVoltageFile; - FILE* socCurrentFile; + FILE* coreVoltageFile {nullptr}; + FILE* coreCurrentFile {nullptr}; + FILE* socVoltageFile {nullptr}; + FILE* socCurrentFile {nullptr}; }; struct CPUPowerData_zenpower : public CPUPowerData { @@ -86,8 +86,8 @@ struct CPUPowerData_zenpower : public CPUPowerData { fclose(this->socPowerFile); }; - FILE* corePowerFile; - FILE* socPowerFile; + FILE* corePowerFile {nullptr}; + FILE* socPowerFile {nullptr}; }; struct CPUPowerData_rapl : public CPUPowerData { @@ -101,7 +101,7 @@ struct CPUPowerData_rapl : public CPUPowerData { fclose(this->energyCounterFile); }; - FILE* energyCounterFile; + FILE* energyCounterFile {nullptr}; int lastCounterValue; Clock::time_point lastCounterValueTime; };