summaryrefslogtreecommitdiff
path: root/kexec
diff options
context:
space:
mode:
authorZhang Yanfei <zhangyanfei@cn.fujitsu.com>2013-03-25 23:15:42 +0800
committerSimon Horman <horms@verge.net.au>2013-03-27 21:41:25 +0900
commitc8bc3a8b369bbe748cbf13a7ccfc1848c4e1d563 (patch)
tree1a8af6a08a22b0b3095aed9bed5ec1bd37020725 /kexec
parent14865de2ea698d1a4a83e90d78437e9309db73e9 (diff)
kexec: ppc: uImage: 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>
Diffstat (limited to 'kexec')
-rw-r--r--kexec/arch/ppc/kexec-uImage-ppc.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/kexec/arch/ppc/kexec-uImage-ppc.c b/kexec/arch/ppc/kexec-uImage-ppc.c
index fd8959c..c4d39f2 100644
--- a/kexec/arch/ppc/kexec-uImage-ppc.c
+++ b/kexec/arch/ppc/kexec-uImage-ppc.c
@@ -81,6 +81,7 @@ static int ppc_load_bare_bits(int argc, char **argv, const char *buf,
unsigned int ep)
{
char *command_line, *cmdline_buf, *crash_cmdline;
+ char *tmp_cmdline;
int command_line_len;
char *dtb;
unsigned int addr;
@@ -101,6 +102,7 @@ static int ppc_load_bare_bits(int argc, char **argv, const char *buf,
cmdline_buf = NULL;
command_line = NULL;
+ tmp_cmdline = NULL;
dtb = NULL;
max_addr = LONG_MAX;
@@ -115,7 +117,7 @@ static int ppc_load_bare_bits(int argc, char **argv, const char *buf,
usage();
return -1;
case OPT_APPEND:
- command_line = optarg;
+ tmp_cmdline = optarg;
break;
case OPT_RAMDISK:
@@ -141,12 +143,12 @@ static int ppc_load_bare_bits(int argc, char **argv, const char *buf,
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;
@@ -295,6 +297,8 @@ out2:
free(cmdline_buf);
out:
free(crash_cmdline);
+ if (!tmp_cmdline)
+ free(command_line);
if (error_msg)
die(error_msg);
return ret;