From 1e22e91dfc392153d14fe55be02963f0f45dc6c8 Mon Sep 17 00:00:00 2001 From: tauon Date: Mon, 8 Dec 2025 23:19:27 -0800 Subject: [PATCH] Free glob buffers after reading thermal zones --- fan-daemon.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fan-daemon.cpp b/fan-daemon.cpp index 4c13ffa..f7ea1d2 100644 --- a/fan-daemon.cpp +++ b/fan-daemon.cpp @@ -93,13 +93,19 @@ unsigned readAverageTemp() glob_t globResult; averageTemp = 0; - glob(THERMAL_ZONE_GLOB, GLOB_TILDE, NULL, &globResult); + if (glob(THERMAL_ZONE_GLOB, GLOB_TILDE, NULL, &globResult) != 0 || globResult.gl_pathc == 0) + { + globfree(&globResult); + return 0; + } for(unsigned i = 0; i < globResult.gl_pathc; ++i) { averageTemp += readIntSysFs(globResult.gl_pathv[i]); } - return (averageTemp / globResult.gl_pathc) / 1000; + averageTemp = (averageTemp / globResult.gl_pathc) / 1000; + globfree(&globResult); + return averageTemp; } /** @@ -144,4 +150,3 @@ void writeIntSysFs(string path, unsigned value) outfs << value; outfs.close(); } -