From: WANG Cong <xiyou.wangcong@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@osdl.org, jdike@addtoit.com,
user-mode-linux-devel@lists.sourceforge.net
Subject: [Patch] arch/um/os-Linux/main.c: Fix memory leaks.
Date: Tue, 01 Apr 2008 23:06:41 +0800 (CST) [thread overview]
Message-ID: <20080401.230641.146239754.xiyou.wangcong@gmail.com> (raw)
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;
}
next reply other threads:[~2008-04-01 15:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-01 15:06 WANG Cong [this message]
2008-04-04 15:49 ` Jeff Dike
2008-04-05 3:15 ` WANG Cong
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=20080401.230641.146239754.xiyou.wangcong@gmail.com \
--to=xiyou.wangcong@gmail.com \
--cc=akpm@osdl.org \
--cc=jdike@addtoit.com \
--cc=linux-kernel@vger.kernel.org \
--cc=user-mode-linux-devel@lists.sourceforge.net \
/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
Powered by JetHome