* [Qemu-devel] [PATCH] cmd: Fix potential memory leak
@ 2011-10-28 21:50 Pavel Borzenkov
0 siblings, 0 replies; only message in thread
From: Pavel Borzenkov @ 2011-10-28 21:50 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial
Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
---
Note, that almost all code in the file violates CODING STYLE. The changed lines
are written wrt CODING STYLE (like commits 7d7d975c and c32d766a).
---
cmd.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/cmd.c b/cmd.c
index abcf206..e1ae5a0 100644
--- a/cmd.c
+++ b/cmd.c
@@ -334,16 +334,21 @@ breakline(
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;
}
--
1.7.0.4
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2011-10-28 21:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-28 21:50 [Qemu-devel] [PATCH] cmd: Fix potential memory leak Pavel Borzenkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).