gdbstub: Fix GDBRegisterState memory leak and use g_new0 to allocate it
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.
Signed-off-by Stefan Weil <[email protected]>
--- gdbstub.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
gdbstub.c +4 -2
@@ -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
Stefan Hajnoczi
AppliedQuoted 10 lines · Stefan Weil
cppcheck reported a memory leak which is fixed here.
I also replaced the corresponding
g_malloc0byg_new0because that helps reviewers, and it is required by latest recommendations anyway.Signed-off-by Stefan Weil <[email protected]>--- 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