Skip to contentSkip to conversation

arch/um/os-Linux/main.c: Fix memory leaks.

PATCH In review WANG Cong 2 participants 3 messages Apr 1, 2008 – Apr 5, 2008 User-mode Linux (UML)

lore
Share & tools
lore

WANG Cong

author
#0 lore raw

PATCH 1/1 arch/um/os-Linux/main.c: Fix memory leaks.

This patch fixes possible memory leaks in the main() function of arch/um/os-Linux/main.c.

---

arch/um/os-Linux/main.c +25 -6
Index: 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
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#1 lore raw
Quoted 3 lines · WANG Cong

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

Signature · 11 lines
Work email - jdike at linux dot intel dot com

-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
author
#2 lore raw

From: Jeff Dike <[email protected]>
Date: Fri, 4 Apr 2008 11:49:01 -0400

Quoted 8 lines · WANG Cong
Quoted 3 lines

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.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Register now and save $200. Hurry, offer ends at 11:59 p.m., Monday, April 7! Use priority code J8TLD2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel