From: Stefan Weil <sw@weilnetz.de>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, Stefan Weil <sw@weilnetz.de>
Subject: [Qemu-devel] [PATCH] gdbstub: Fix GDBRegisterState memory leak and use g_new0 to allocate it
Date: Thu, 17 Nov 2011 19:22:58 +0100 [thread overview]
Message-ID: <1321554178-12486-1-git-send-email-sw@weilnetz.de> (raw)
cppcheck reported a memory leak which is fixed here.
I also replaced the corresponding g_malloc0 by g_new0 because
that helps reviewers, and it is required by latest recommendations
anyway.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
gdbstub.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/gdbstub.c b/gdbstub.c
index a25f404..031a240 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1781,7 +1781,7 @@ void gdb_register_coprocessor(CPUState * env,
GDBRegisterState **p;
static int last_reg = NUM_CORE_REGS;
- s = (GDBRegisterState *)g_malloc0(sizeof(GDBRegisterState));
+ s = g_new0(GDBRegisterState, 1);
s->base_reg = last_reg;
s->num_regs = num_regs;
s->get_reg = get_reg;
@@ -1790,8 +1790,10 @@ void gdb_register_coprocessor(CPUState * env,
p = &env->gdb_regs;
while (*p) {
/* Check for duplicates. */
- if (strcmp((*p)->xml, xml) == 0)
+ if (strcmp((*p)->xml, xml) == 0) {
+ g_free(s);
return;
+ }
p = &(*p)->next;
}
/* Add to end of list. */
--
1.7.2.5
next reply other threads:[~2011-11-17 18:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-17 18:22 Stefan Weil [this message]
2011-11-18 11:32 ` [Qemu-devel] [Qemu-trivial] [PATCH] gdbstub: Fix GDBRegisterState memory leak and use g_new0 to allocate it Stefan Hajnoczi
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=1321554178-12486-1-git-send-email-sw@weilnetz.de \
--to=sw@weilnetz.de \
--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).