diff options
author | Zhang Yanfei <zhangyanfei@cn.fujitsu.com> | 2013-03-25 23:11:29 +0800 |
---|---|---|
committer | Simon Horman <horms@verge.net.au> | 2013-03-27 21:38:17 +0900 |
commit | 2021c0000d300159e7e3e32add438289f904542c (patch) | |
tree | 0650d9935ba5e666ba824d83d5081a963eabb504 | |
parent | ea271e8b667fdb14f6ca89a00a1885ca94c24647 (diff) | |
download | kexec-tools-2021c0000d300159e7e3e32add438289f904542c.tar.gz |
kexec: i386: multiboot: 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-multiboot-x86.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/kexec/arch/i386/kexec-multiboot-x86.c b/kexec/arch/i386/kexec-multiboot-x86.c index 4252f759..4520fd7f 100644 --- a/kexec/arch/i386/kexec-multiboot-x86.c +++ b/kexec/arch/i386/kexec-multiboot-x86.c @@ -147,7 +147,7 @@ int multiboot_x86_load(int argc, char **argv, const char *buf, off_t len, unsigned long mbi_base; struct entry32_regs regs; size_t mbi_bytes, mbi_offset; - char *command_line = NULL; + char *command_line = NULL, *tmp_cmdline = NULL; char *imagename, *cp, *append = NULL;; struct memory_range *range; int ranges; @@ -195,7 +195,7 @@ int multiboot_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_MOD: modules++; @@ -204,7 +204,10 @@ int multiboot_x86_load(int argc, char **argv, const char *buf, off_t len, } } imagename = argv[optind]; - command_line = concat_cmdline(command_line, append); + command_line = concat_cmdline(tmp_cmdline, append); + if (tmp_cmdline) { + free(tmp_cmdline); + } command_line_len = strlen(command_line) + strlen(imagename) + 2; /* Load the ELF executable */ |