[PATCH] objtool: Fix memleak in disas_warned_funcs() and disas_funcs()

From: Yi Yang
Date: Thu Jun 12 2025 - 04:25:05 EST


Variable "cmd" and "funcs" which is allocated by malloc is not freed in
all paths, fix this by freeing them after use.

Fixes: ca653464dd09 ("objtool: Add verbose option for disassembling affected functions")
Signed-off-by: Yi Yang <yiyang13@xxxxxxxxxx>
---
tools/objtool/check.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index f23bdda737aa..1e8a14e23d0e 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -4605,10 +4605,12 @@ static void disas_funcs(const char *funcs)
/* real snprintf() */
snprintf(cmd, size, objdump_str, cross_compile, objname, funcs);
ret = system(cmd);
+ free(cmd);
if (ret) {
WARN("disassembly failed: %d", ret);
return;
}
+
}

static void disas_warned_funcs(struct objtool_file *file)
@@ -4629,6 +4631,7 @@ static void disas_warned_funcs(struct objtool_file *file)
tmp = malloc(strlen(funcs) + strlen(sym->name) + 2);
if (!tmp) {
ERROR_GLIBC("malloc");
+ free(funcs);
return;
}
sprintf(tmp, "%s %s", funcs, sym->name);
@@ -4638,8 +4641,10 @@ static void disas_warned_funcs(struct objtool_file *file)
}
}

- if (funcs)
+ if (funcs) {
disas_funcs(funcs);
+ free(funcs);
+ }
}

struct insn_chunk {
--
2.25.1