[PATCH v3 28/28] fixup! objtool: Add options to write/read exported noreturns to/from a file

From
Josh Poimboeuf <jpoimboe@kernel.org>
Date
2026-09-21 22:31:52
Also in
linux-kbuild, lkml
Reply to
Josh Poimboeuf, 2026-09-21
Fix resource leaks on error paths in write_noreturns(): free buf on
fopen() failure, and free buf + fclose fp on fwrite() failure.

Found by Sashiko review.

Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 tools/objtool/check.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 626402023e4a3..8d1448cdb40ca 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -350,11 +350,14 @@ static int write_noreturns(struct objtool_file *file)
 	fp = fopen(opts.noreturns_write, "w");
 	if (!fp) {
 		ERROR_GLIBC("fopen");
+		free(buf);
 		return -1;
 	}
 
 	if (fwrite(buf, 1, len, fp) != len) {
 		ERROR_GLIBC("fwrite");
+		free(buf);
+		fclose(fp);
 		return -1;
 	}
 
-- 
2.55.0
Thread (34 messages) 34 messages, 2 authors, last reply 2026-09-24
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help