[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250612081539.257339-1-yiyang13@huawei.com>
Date: Thu, 12 Jun 2025 08:15:39 +0000
From: Yi Yang <yiyang13@...wei.com>
To: <jpoimboe@...nel.org>, <peterz@...radead.org>, <mbenes@...e.cz>
CC: <linux-kernel@...r.kernel.org>, <lujialin4@...wei.com>
Subject: [PATCH] objtool: Fix memleak in disas_warned_funcs() and disas_funcs()
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@...wei.com>
---
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
Powered by blists - more mailing lists