[PATCH] tools/thermal/thermometer: close fd on realloc failure

From: amarjeet

Date: Sat Jun 20 2026 - 03:42:47 EST


From: Amarjeet <amarjeet@xxxxxxxxx>

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.

Signed-off-by: Amarjeet <amarjeet@xxxxxxxxx>
---
tools/thermal/thermometer/thermometer.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/tools/thermal/thermometer/thermometer.c b/tools/thermal/thermometer/thermometer.c
index 022865da8e3c..103db7a2a8e4 100644
--- a/tools/thermal/thermometer/thermometer.c
+++ b/tools/thermal/thermometer/thermometer.c
@@ -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;
}

--
2.34.1