From: lumingyindetect@163.com
To: linux-kernel@vger.kernel.org
Cc: peterz@infradead.org
Subject: Re:[PATCH] tools:Fix a memory leak bug related to the cmd
Date: Sun, 24 Mar 2024 13:56:06 +0800 (CST) [thread overview]
Message-ID: <17ddf389.9f7.18e6f07cfff.Coremail.lumingyindetect@163.com> (raw)
In-Reply-To: <20240323065550.603005-1-lumingyindetect@163.com>
Thank you for your prompt response! It is indeed a wise decision not to release dynamic memory when the tool runs briefly and encounters errors. However, I also noticed in the disas_funcs function in the /linux/tools/objtool/check.c file (line 4617) that a variable named cmd pointing to a dynamic memory area is not being freed (regardless of whether an error occurs). In this case, would it be necessary to add a free(cmd)?
在 2024-03-23 14:55:50,LuMingYin <lumingyindetect@163.com> 写道:
In the function 'disas_funcs' defined in the file /linux/tools/objtool/check.c, a pointer variable named 'cmd' is declared (line 4583 of the file). This pointer variable allocates a block of dynamic memory using the 'malloc' function at line 4615. However, after using the memory area pointed to by 'cmd' (line 4619), it is not deallocated, resulting in a memory leak bug. This commit fixes the bug.
Signed-off-by: LuMingYin <lumingyindetect@163.com>
---
tools/objtool/check.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index eb7e12ebc1d0..486a2a6374f5 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -4617,6 +4617,7 @@ static int 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 -1;
--
2.25.1
next prev parent reply other threads:[~2024-03-24 5:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-23 6:55 [PATCH] " LuMingYin
2024-03-24 5:56 ` lumingyindetect [this message]
2024-04-28 8:52 ` [PATCH] tools: Fix a memory leak in disas_funcs() Markus Elfring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=17ddf389.9f7.18e6f07cfff.Coremail.lumingyindetect@163.com \
--to=lumingyindetect@163.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®