summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhang Yanfei <zhangyanfei@cn.fujitsu.com>2013-03-25 23:09:01 +0800
committerSimon Horman <horms@verge.net.au>2013-03-27 21:36:54 +0900
commitd5b18a8f276abfc2008729252582edf87a8544ee (patch)
tree181c31219e9d5986767f228baac8bbcf9fef153e
parent40e7f33864a9090dceef798cc856bf38f72ca15b (diff)
downloadkexec-tools-d5b18a8f276abfc2008729252582edf87a8544ee.tar.gz
kexec: i386: elf: fix memory leak caused by get_command_line
Since get_command_line returns dynamically allocated memory, it is easy for the caller to forget freeing the memory. Here fixes a memory leak caused by this function. Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com> Signed-off-by: Simon Horman <horms@verge.net.au>
-rw-r--r--kexec/arch/i386/kexec-elf-x86.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/kexec/arch/i386/kexec-elf-x86.c b/kexec/arch/i386/kexec-elf-x86.c
index de855c46..94571caa 100644
--- a/kexec/arch/i386/kexec-elf-x86.c
+++ b/kexec/arch/i386/kexec-elf-x86.c
@@ -90,6 +90,7 @@ int elf_x86_load(int argc, char **argv, const char *buf, off_t len,
struct mem_ehdr ehdr;
char *command_line = NULL, *modified_cmdline = NULL;
const char *append = NULL;
+ char *tmp_cmdline = NULL;
char *error_msg = NULL;
int result;
int command_line_len;
@@ -139,7 +140,7 @@ int elf_x86_load(int argc, char **argv, const char *buf, off_t len,
append = optarg;
break;
case OPT_REUSE_CMDLINE:
- command_line = get_command_line();
+ tmp_cmdline = get_command_line();
break;
case OPT_RAMDISK:
ramdisk = optarg;
@@ -159,7 +160,10 @@ int elf_x86_load(int argc, char **argv, const char *buf, off_t len,
break;
}
}
- command_line = concat_cmdline(command_line, append);
+ command_line = concat_cmdline(tmp_cmdline, append);
+ if (tmp_cmdline) {
+ free(tmp_cmdline);
+ }
command_line_len = 0;
if (command_line) {
command_line_len = strlen(command_line) +1;