From 47e8dd8fe9d83e8b51d40c2b87d7983bd0a78206 Mon Sep 17 00:00:00 2001 From: Pavel Borzenkov Date: Mon, 31 Oct 2011 22:53:38 +0400 Subject: [PATCH] cmd: Fix potential memory leak Signed-off-by: Pavel Borzenkov Signed-off-by: Stefan Hajnoczi --- cmd.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd.c b/cmd.c index 75415d86a2..0806e18ce0 100644 --- a/cmd.c +++ b/cmd.c @@ -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;