From c1acf0ea9eb746cf6d9d9a42d79245f721ed2e96 Mon Sep 17 00:00:00 2001 From: Zhang Yanfei Date: Mon, 25 Mar 2013 23:17:29 +0800 Subject: kexec: x86_64: 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 Signed-off-by: Simon Horman --- kexec/arch/x86_64/kexec-elf-x86_64.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kexec/arch/x86_64/kexec-elf-x86_64.c b/kexec/arch/x86_64/kexec-elf-x86_64.c index a3fc728..4a41780 100644 --- a/kexec/arch/x86_64/kexec-elf-x86_64.c +++ b/kexec/arch/x86_64/kexec-elf-x86_64.c @@ -89,6 +89,7 @@ int elf_x86_64_load(int argc, char **argv, const char *buf, off_t len, struct mem_ehdr ehdr; const char *append = NULL; char *command_line = NULL, *modified_cmdline; + char *tmp_cmdline = NULL; int command_line_len; const char *ramdisk; unsigned long entry, max_addr; @@ -135,7 +136,7 @@ int elf_x86_64_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; @@ -155,7 +156,9 @@ int elf_x86_64_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; -- cgit