qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cpu: fix memleak of 'halt_cond' and 'thread'
@ 2024-06-12 17:04 Matheus Tavares Bernardino
  2024-06-13  9:39 ` Philippe Mathieu-Daudé
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Matheus Tavares Bernardino @ 2024-06-12 17:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: alex.bennee, pierrick.bouvier, philmd, qemu-trivial,
	Richard Henderson, Paolo Bonzini, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang

Since a4c2735f35 (cpu: move Qemu[Thread|Cond] setup into common code,
2024-05-30) these fields are now allocated at cpu_common_initfn(). So
let's make sure we also free them at cpu_common_finalize().

Furthermore, the code also frees these on round robin, but we missed
'halt_cond'.

Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
---
 accel/tcg/tcg-accel-ops-rr.c | 1 +
 hw/core/cpu-common.c         | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c
index 84c36c1450..48c38714bd 100644
--- a/accel/tcg/tcg-accel-ops-rr.c
+++ b/accel/tcg/tcg-accel-ops-rr.c
@@ -329,6 +329,7 @@ void rr_start_vcpu_thread(CPUState *cpu)
         /* we share the thread, dump spare data */
         g_free(cpu->thread);
         qemu_cond_destroy(cpu->halt_cond);
+        g_free(cpu->halt_cond);
         cpu->thread = single_tcg_cpu_thread;
         cpu->halt_cond = single_tcg_halt_cond;
 
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index bf1a7b8892..f131cde2c0 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -286,6 +286,9 @@ static void cpu_common_finalize(Object *obj)
     g_array_free(cpu->gdb_regs, TRUE);
     qemu_lockcnt_destroy(&cpu->in_ioctl_lock);
     qemu_mutex_destroy(&cpu->work_mutex);
+    qemu_cond_destroy(cpu->halt_cond);
+    g_free(cpu->halt_cond);
+    g_free(cpu->thread);
 }
 
 static int64_t cpu_common_get_arch_id(CPUState *cpu)
-- 
2.37.2



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

end of thread, other threads:[~2024-06-17 12:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-12 17:04 [PATCH] cpu: fix memleak of 'halt_cond' and 'thread' Matheus Tavares Bernardino
2024-06-13  9:39 ` Philippe Mathieu-Daudé
2024-06-14 17:49 ` Pierrick Bouvier
2024-06-17 12:48 ` Michael Tokarev

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