diff options
author | Pavel Borzenkov <pavel.borzenkov@gmail.com> | 2011-10-31 22:53:38 +0400 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> | 2011-11-07 08:01:15 +0000 |
commit | 47e8dd8fe9d83e8b51d40c2b87d7983bd0a78206 (patch) | |
tree | d4f0aae3104802dd9166634db2bbd04c603876cc /cmd.c | |
parent | ba7806ad92a2f6b1625cfa67d44dc1b71e3be44e (diff) |
cmd: Fix potential memory leak
Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Diffstat (limited to 'cmd.c')
-rw-r--r-- | cmd.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -329,16 +329,21 @@ char **breakline(char *input, int *count) int c = 0; char *p; char **rval = calloc(sizeof(char *), 1); + char **tmp; while (rval && (p = qemu_strsep(&input, " ")) != NULL) { if (!*p) { continue; } c++; - rval = realloc(rval, sizeof(*rval) * (c + 1)); - if (!rval) { + tmp = realloc(rval, sizeof(*rval) * (c + 1)); + if (!tmp) { + free(rval); + rval = NULL; c = 0; break; + } else { + rval = tmp; } rval[c - 1] = p; rval[c] = NULL; |