Skip to content

Commit

Permalink
cmd: Fix potential memory leak
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Borzenkov <[email protected]>
Signed-off-by: Stefan Hajnoczi <[email protected]>
  • Loading branch information
pborzenkov authored and Stefan Hajnoczi committed Nov 7, 2011
1 parent ba7806a commit 47e8dd8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 47e8dd8

Please sign in to comment.