diff options
author | Simon Horman <horms@verge.net.au> | 2010-02-02 14:42:02 +1100 |
---|---|---|
committer | Simon Horman <horms@verge.net.au> | 2010-02-02 14:42:02 +1100 |
commit | c59af3ab34f41f259eb2f019e9f5f9ad3229893f (patch) | |
tree | 84828e87eccb5a3ee289e10e029bb0820ed655c1 /kexec/kexec.c | |
parent | 8b42c99aa3bc59b877732a82e6db6380e4958b54 (diff) |
don't leak in concat_cmdline
Cc: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Simon Horman <horms@verge.net.au>
Diffstat (limited to 'kexec/kexec.c')
-rw-r--r-- | kexec/kexec.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/kexec/kexec.c b/kexec/kexec.c index f4c22a6..db73b0e 100644 --- a/kexec/kexec.c +++ b/kexec/kexec.c @@ -62,6 +62,14 @@ void die(char *fmt, ...) exit(1); } +char *xstrdup(const char *str) +{ + char *new = strdup(str); + if (!new) + die("Cannot strdup \"%s\": %s\n", + str, strerror(errno)); + return new; +} void *xmalloc(size_t size) { @@ -994,15 +1002,15 @@ void check_reuse_initrd(void) free(line); } -const char *concat_cmdline(const char *base, const char *append) +char *concat_cmdline(const char *base, const char *append) { - const char *cmdline; + char *cmdline; if (!base && !append) return NULL; - if (!base) - return append; - if (!append) - return base; + if (append) + return xstrdup(append); + if (base) + return xstrdup(base); cmdline = xmalloc(strlen(base) + 1 + strlen(append) + 1); strcpy(cmdline, base); strcat(cmdline, " "); |