* [Qemu-devel] [PATCH] gdbstub: Fix GDBRegisterState memory leak and use g_new0 to allocate it
@ 2011-11-17 18:22 Stefan Weil
2011-11-18 11:32 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Weil @ 2011-11-17 18:22 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Stefan Weil
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH] gdbstub: Fix GDBRegisterState memory leak and use g_new0 to allocate it
2011-11-17 18:22 [Qemu-devel] [PATCH] gdbstub: Fix GDBRegisterState memory leak and use g_new0 to allocate it Stefan Weil
@ 2011-11-18 11:32 ` Stefan Hajnoczi
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2011-11-18 11:32 UTC (permalink / raw)
To: Stefan Weil; +Cc: qemu-trivial, qemu-devel
On Thu, Nov 17, 2011 at 07:22:58PM +0100, Stefan Weil wrote:
> 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(-)
Thanks, applied to the trivial patches -next tree:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/trivial-patches-next
Stefan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-11-18 11:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-17 18:22 [Qemu-devel] [PATCH] gdbstub: Fix GDBRegisterState memory leak and use g_new0 to allocate it Stefan Weil
2011-11-18 11:32 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
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).