linux-um archives
 help / color / mirror / Atom feed
* [uml-devel] [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;
 }

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-04-05  3:18 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 [uml-devel] [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