mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tools/thermal/thermometer: close fd on realloc failure
@ 2026-06-20  7:41 amarjeet
  2026-06-20 12:26 ` [PATCH v2] " amarjeet
  0 siblings, 1 reply; 3+ messages in thread
From: amarjeet @ 2026-06-20  7:41 UTC (permalink / raw)
  To: Rafael J . Wysocki, Daniel Lezcano
  Cc: Zhang Rui, Lukasz Luba, linux-pm, linux-kernel

From: Amarjeet <amarjeet@intel.com>

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@intel.com>
---
 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-22 15:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-20  7:41 [PATCH] tools/thermal/thermometer: close fd on realloc failure amarjeet
2026-06-20 12:26 ` [PATCH v2] " amarjeet
2026-07-22 15:44   ` Rafael J. Wysocki (Intel)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®