tools/thermal/thermometer: close fd on realloc failure
PATCH 1/1 tools/thermal/thermometer: close fd on realloc failure
From: Amarjeet <[email protected]>
thermometer_add_tz() opens tz_path and then reallocates thermometer->tz. If realloc fails, the function returns without closing fd.
Close fd before returning on realloc failure to avoid leaking a file descriptor.
--- tools/thermal/thermometer/thermometer.c | 1 + 1 file changed, 1 insertion(+)
tools/thermal/thermometer/thermometer.c +1 -0
@@ -266,6 +266,7 @@ static int thermometer_add_tz(const char *path, const char *name, int polling, fd =open (tz_path,O_RDONLY );if (fd <0 ) {ERROR ("Failed to open '%s': %m\n" , tz_path); +close (fd);return -1 ; }
Signature · 1 line
2.34.1
PATCH v2 1/1 tools/thermal/thermometer: close fd on realloc failure
From: Amarjeet <[email protected]>
thermometer_add_tz() opens tz_path and then reallocates thermometer->tz. If realloc fails, the function returns without closing fd.
Close fd before returning on realloc failure to avoid leaking a file descriptor.
---
v2:
- drop close(fd) on open() failure path
- keep close(fd) only on realloc failure path
--- tools/thermal/thermometer/thermometer.c | 1 + 1 file changed, 1 insertion(+)
tools/thermal/thermometer/thermometer.c +1 -0
@@ -272,6 +272,7 @@ static int thermometer_add_tz(const char *path, const char *name, int polling, tz =realloc (thermometer->tz,sizeof (*thermometer->tz) * (thermometer->nr_tz +1 ));if (!tz) {ERROR ("Failed to allocate thermometer->tz\n" ); +close (fd);return -1 ; }
Signature · 1 line
2.34.1
Quoted 23 lines · On Sat, Jun 20, 2026 at 2:27 PM <[email protected]> wrote:
From: Amarjeet <[email protected]>
thermometer_add_tz()openstz_pathand then reallocatesthermometer->tz. If realloc fails, the function returns without closing fd.Close fd before returning on realloc failure to avoid leaking a file descriptor.
Signed-off-by Amarjeet <[email protected]>---
v2:
- drop close(fd) onopen()failure path
- keep close(fd) only on realloc failure path--- tools/thermal/thermometer/thermometer.c | 1 + 1 file changed, 1 insertion(+)tools/thermal/thermometer/thermometer.c +0
-0
tools/thermal/thermometer/thermometer.c static int thermometer_add_tz(const char *path, const char *name, int polling,
Quoted 8 lines
tools/thermal/thermometer/thermometer.c +1
-1@@ -272,6 +272,7 @@ static int thermometer_add_tz(const char *path, const char *name, int polling, tz =realloc (thermometer->tz,sizeof (*thermometer->tz) * (thermometer->nr_tz +1 ));if (!tz) {ERROR ("Failed to allocate thermometer->tz\n" ); +close (fd);return -1 ; } --
Applied as 7.3 material, thanks!