LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [Patch] arch/um/os-Linux/main.c: Fix memory leaks.
@ 2008-04-01 15:06 WANG Cong
2008-04-04 15:49 ` Jeff Dike
0 siblings, 1 reply; 3+ messages in thread
From: WANG Cong @ 2008-04-01 15:06 UTC (permalink / raw)
To: linux-kernel; +Cc: akpm, jdike, user-mode-linux-devel
This patch fixes possible memory leaks in the main() function of
arch/um/os-Linux/main.c.
Cc: jdike@addtoit.com
Signed-off-by: WANG Cong <wangcong@zeuux.org>
---
Index: linux-2.6/arch/um/os-Linux/main.c
===================================================================
--- linux-2.6.orig/arch/um/os-Linux/main.c
+++ linux-2.6/arch/um/os-Linux/main.c
@@ -113,14 +113,10 @@ static void setup_env_path(void)
extern void scan_elf_aux( char **envp);
-int __init main(int argc, char **argv, char **envp)
+static char** dup_argv(int argc, char **argv)
{
+ int i;
char **new_argv;
- int ret, i, err;
-
- set_stklim();
-
- setup_env_path();
new_argv = malloc((argc + 1) * sizeof(char *));
if (new_argv == NULL) {
@@ -135,6 +131,28 @@ int __init main(int argc, char **argv, c
}
}
new_argv[argc] = NULL;
+ return new_argv;
+}
+
+static void free_argv(int argc, char **argv)
+{
+ int i;
+ for (i = 0; i < argc; i++) {
+ free(argv[i]);
+ }
+ free(argv);
+}
+
+int __init main(int argc, char **argv, char **envp)
+{
+ char **new_argv;
+ int ret, i, err;
+
+ set_stklim();
+
+ setup_env_path();
+
+ new_argv = dup_argv(argc, argv);
/*
* Allow these signals to bring down a UML if all other
@@ -185,6 +203,7 @@ int __init main(int argc, char **argv, c
perror("Failed to exec kernel");
ret = 1;
}
+ free_argv(argc, new_argv);
printf("\n");
return uml_exitcode;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Patch] arch/um/os-Linux/main.c: Fix memory leaks.
2008-04-01 15:06 [Patch] arch/um/os-Linux/main.c: Fix memory leaks WANG Cong
@ 2008-04-04 15:49 ` Jeff Dike
2008-04-05 3:15 ` WANG Cong
0 siblings, 1 reply; 3+ messages in thread
From: Jeff Dike @ 2008-04-04 15:49 UTC (permalink / raw)
To: WANG Cong; +Cc: linux-kernel, akpm, user-mode-linux-devel
On Tue, Apr 01, 2008 at 11:06:41PM +0800, WANG Cong wrote:
>
> This patch fixes possible memory leaks in the main() function of
> arch/um/os-Linux/main.c.
I'm somewhat dubious about this - the memory is freed immediately
before exiting, making this patch have no practical effect.
Jeff
--
Work email - jdike at linux dot intel dot com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Patch] arch/um/os-Linux/main.c: Fix memory leaks.
2008-04-04 15:49 ` Jeff Dike
@ 2008-04-05 3:15 ` WANG Cong
0 siblings, 0 replies; 3+ messages in thread
From: WANG Cong @ 2008-04-05 3:15 UTC (permalink / raw)
To: jdike; +Cc: linux-kernel, akpm, user-mode-linux-devel
From: Jeff Dike <jdike@addtoit.com>
Date: Fri, 4 Apr 2008 11:49:01 -0400
> On Tue, Apr 01, 2008 at 11:06:41PM +0800, WANG Cong wrote:
> >
> > This patch fixes possible memory leaks in the main() function of
> > arch/um/os-Linux/main.c.
>
> I'm somewhat dubious about this - the memory is freed immediately
> before exiting, making this patch have no practical effect.
>
I think all memory leaks indicate our logic is not right, although
this one maybe harmless.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-04-05 3:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-01 15:06 [Patch] arch/um/os-Linux/main.c: Fix memory leaks WANG Cong
2008-04-04 15:49 ` Jeff Dike
2008-04-05 3:15 ` WANG Cong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).