diff options
author | Zhang Yanfei <zhangyanfei@cn.fujitsu.com> | 2013-03-25 23:13:40 +0800 |
---|---|---|
committer | Simon Horman <horms@verge.net.au> | 2013-03-27 21:40:33 +0900 |
commit | e640d91329a3a227476fa0a1355b07291c2dac3d (patch) | |
tree | 590d77697dff9c5d2121886f39be743d242a5d10 | |
parent | 90262d432f138506ee2929f74b679160c73626ea (diff) | |
download | kexec-tools-e640d91329a3a227476fa0a1355b07291c2dac3d.tar.gz |
kexec: ppc: 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/ppc/kexec-elf-ppc.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/kexec/arch/ppc/kexec-elf-ppc.c b/kexec/arch/ppc/kexec-elf-ppc.c index 1eb3a625..694befb0 100644 --- a/kexec/arch/ppc/kexec-elf-ppc.c +++ b/kexec/arch/ppc/kexec-elf-ppc.c @@ -156,6 +156,7 @@ int elf_ppc_load(int argc, char **argv, const char *buf, off_t len, { struct mem_ehdr ehdr; char *command_line, *crash_cmdline, *cmdline_buf; + char *tmp_cmdline; int command_line_len; char *dtb; int result; @@ -191,7 +192,7 @@ int elf_ppc_load(int argc, char **argv, const char *buf, off_t len, char *blob_buf = NULL; off_t blob_size = 0; - command_line = NULL; + command_line = tmp_cmdline = NULL; dtb = NULL; max_addr = LONG_MAX; hole_addr = 0; @@ -211,7 +212,7 @@ int elf_ppc_load(int argc, char **argv, const char *buf, off_t len, usage(); return -1; case OPT_APPEND: - command_line = optarg; + tmp_cmdline = optarg; break; case OPT_RAMDISK: ramdisk = optarg; @@ -239,12 +240,12 @@ int elf_ppc_load(int argc, char **argv, const char *buf, off_t len, die("Can't specify --ramdisk or --initrd with --reuseinitrd\n"); command_line_len = 0; - if (command_line) { - command_line_len = strlen(command_line) + 1; + if (tmp_cmdline) { + command_line = tmp_cmdline; } else { command_line = get_command_line(); - command_line_len = strlen(command_line) + 1; } + command_line_len = strlen(command_line) + 1; fixup_nodes[cur_fixup] = NULL; @@ -450,6 +451,8 @@ out2: out: free_elf_info(&ehdr); free(crash_cmdline); + if (!tmp_cmdline) + free(command_line); if (error_msg) die(error_msg); |