* [PATCH] tools:Fix a memory leak bug related to the cmd
@ 2024-03-23 6:55 LuMingYin
2024-03-24 5:56 ` lumingyindetect
2024-04-28 8:52 ` [PATCH] tools: Fix a memory leak in disas_funcs() Markus Elfring
0 siblings, 2 replies; 3+ messages in thread
From: LuMingYin @ 2024-03-23 6:55 UTC (permalink / raw)
To: linux-kernel; +Cc: peterz, LuMingYin
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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re:[PATCH] tools:Fix a memory leak bug related to the cmd
2024-03-23 6:55 [PATCH] tools:Fix a memory leak bug related to the cmd LuMingYin
@ 2024-03-24 5:56 ` lumingyindetect
2024-04-28 8:52 ` [PATCH] tools: Fix a memory leak in disas_funcs() Markus Elfring
1 sibling, 0 replies; 3+ messages in thread
From: lumingyindetect @ 2024-03-24 5:56 UTC (permalink / raw)
To: linux-kernel; +Cc: peterz
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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] tools: Fix a memory leak in disas_funcs()
2024-03-23 6:55 [PATCH] tools:Fix a memory leak bug related to the cmd LuMingYin
2024-03-24 5:56 ` lumingyindetect
@ 2024-04-28 8:52 ` Markus Elfring
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2024-04-28 8:52 UTC (permalink / raw)
To: LuMingYin
Cc: LuMingYin, LKML, kernel-janitors, Josh Poimboeuf, Peter Zijlstra
…
> 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.
Please take advices from known information sources better into account.
* https://kernelnewbies.org/FirstKernelPatch
* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.9-rc5#n3
I got the impression that Josh Poimboeuf answered your development concern already.
https://lore.kernel.org/lkml/20240323182209.xqzb6rsswvfbg74n@treble/
https://lkml.org/lkml/2024/3/23/285
Would you like to support faster execution of the mentioned program
so that manual memory releases can be omitted so far?
Did your email address change in the meantime?
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-28 8:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-23 6:55 [PATCH] tools:Fix a memory leak bug related to the cmd LuMingYin
2024-03-24 5:56 ` lumingyindetect
2024-04-28 8:52 ` [PATCH] tools: Fix a memory leak in disas_funcs() Markus Elfring
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®