qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] gdbstub: Fix memory leak
@ 2011-10-17 20:01 Stefan Weil
  2011-10-18  1:13 ` Stuart Brady
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Weil @ 2011-10-17 20:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: Stefan Weil

cppcheck report:
  gdbstub.c:1781: error: Memory leak: s

Rearranging of the code avoids the leak.

The patch also slightly cleans the g_malloc0 statement which was
touched by that change (no type cast, easier code review).

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 gdbstub.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 4009058..34746f2 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1768,12 +1768,6 @@ void gdb_register_coprocessor(CPUState * env,
     GDBRegisterState **p;
     static int last_reg = NUM_CORE_REGS;
 
-    s = (GDBRegisterState *)g_malloc0(sizeof(GDBRegisterState));
-    s->base_reg = last_reg;
-    s->num_regs = num_regs;
-    s->get_reg = get_reg;
-    s->set_reg = set_reg;
-    s->xml = xml;
     p = &env->gdb_regs;
     while (*p) {
         /* Check for duplicates.  */
@@ -1781,6 +1775,14 @@ void gdb_register_coprocessor(CPUState * env,
             return;
         p = &(*p)->next;
     }
+
+    s = g_malloc0(sizeof(*s));
+    s->base_reg = last_reg;
+    s->num_regs = num_regs;
+    s->get_reg = get_reg;
+    s->set_reg = set_reg;
+    s->xml = xml;
+
     /* Add to end of list.  */
     last_reg += num_regs;
     *p = s;
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-11-19 13:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-17 20:01 [Qemu-devel] [PATCH] gdbstub: Fix memory leak Stefan Weil
2011-10-18  1:13 ` Stuart Brady
2011-10-18 18:18   ` Blue Swirl
2011-10-19  0:59     ` Stuart Brady
2011-10-20  8:10       ` Stuart Brady
2011-10-23 12:48         ` Blue Swirl
2011-10-18 20:25   ` [Qemu-devel] [PATCH v2] " Stefan Weil
2011-11-11 21:09     ` Stefan Weil
2011-11-19 13:59       ` Blue Swirl

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).