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:
parent
ba7806ad92
commit
47e8dd8fe9
9
cmd.c
9
cmd.c
@ -329,16 +329,21 @@ char **breakline(char *input, int *count)
|
|||||||
int c = 0;
|
int c = 0;
|
||||||
char *p;
|
char *p;
|
||||||
char **rval = calloc(sizeof(char *), 1);
|
char **rval = calloc(sizeof(char *), 1);
|
||||||
|
char **tmp;
|
||||||
|
|
||||||
while (rval && (p = qemu_strsep(&input, " ")) != NULL) {
|
while (rval && (p = qemu_strsep(&input, " ")) != NULL) {
|
||||||
if (!*p) {
|
if (!*p) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
c++;
|
c++;
|
||||||
rval = realloc(rval, sizeof(*rval) * (c + 1));
|
tmp = realloc(rval, sizeof(*rval) * (c + 1));
|
||||||
if (!rval) {
|
if (!tmp) {
|
||||||
|
free(rval);
|
||||||
|
rval = NULL;
|
||||||
c = 0;
|
c = 0;
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
rval = tmp;
|
||||||
}
|
}
|
||||||
rval[c - 1] = p;
|
rval[c - 1] = p;
|
||||||
rval[c] = NULL;
|
rval[c] = NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user