Skip to contentSkip to conversation

gdbstub: Fix GDBRegisterState memory leak and use g_new0 to allocate it

PATCH Applied Stefan Weil 2 participants 2 messages Nov 17, 2011 – Nov 18, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gdbstub: Fix GDBRegisterState memory leak and use g_new0 to allocate it

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.

---
 gdbstub.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
gdbstub.c +4 -2
index a25f404..031a240 100644
@@ -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.  */
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 10 lines · 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.

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