diff options
-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; |