sim-card
/
qemu
Archived
10
0
Fork 0

cmd: Fix potential memory leak

Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
This commit is contained in:
Pavel Borzenkov 2011-10-31 22:53:38 +04:00 committed by Stefan Hajnoczi
parent ba7806ad92
commit 47e8dd8fe9
1 changed files with 7 additions and 2 deletions

9
cmd.c
View File

@ -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;