aboutsummaryrefslogtreecommitdiff
path: root/gdbstub.c
diff options
context:
space:
mode:
authorStefan Weil <sw@weilnetz.de>2011-10-18 22:25:38 +0200
committerBlue Swirl <blauwirbel@gmail.com>2011-11-19 11:22:24 +0000
commit9643c25f8d67646857159d6fc021b07e7a659192 (patch)
tree3ce5f4b6a32c0d3dd814e27937a11d3334680dfe /gdbstub.c
parentb08d26b76d51fb2695912373ded53b628ec96320 (diff)
downloadqemu-9643c25f8d67646857159d6fc021b07e7a659192.zip
qemu-9643c25f8d67646857159d6fc021b07e7a659192.tar.gz
qemu-9643c25f8d67646857159d6fc021b07e7a659192.tar.bz2
gdbstub: Fix memory leak
cppcheck report: gdbstub.c:1781: error: Memory leak: s Rearranging of the code avoids the leak. v2: Replace the g_malloc0() by g_new0() (suggested by Stuart Brady). Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Diffstat (limited to 'gdbstub.c')
-rw-r--r--gdbstub.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/gdbstub.c b/gdbstub.c
index a25f404..640cf4e 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1781,12 +1781,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. */
@@ -1794,6 +1788,14 @@ void gdb_register_coprocessor(CPUState * env,
return;
p = &(*p)->next;
}
+
+ s = g_new0(GDBRegisterState, 1);
+ 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;