From: Pavel Borzenkov <pavel.borzenkov@gmail.com>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org
Subject: [Qemu-devel] [PATCH] cmd: Fix potential memory leak
Date: Sat, 29 Oct 2011 01:50:33 +0400 [thread overview]
Message-ID: <1319838633-25493-1-git-send-email-pavel.borzenkov@gmail.com> (raw)
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
reply other threads:[~2011-10-28 21:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1319838633-25493-1-git-send-email-pavel.borzenkov@gmail.com \
--to=pavel.borzenkov@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).