]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
cpu: Free queued CPU work
authorAkihiko Odaki <akihiko.odaki@daynix.com>
Sun, 14 Jul 2024 10:46:52 +0000 (19:46 +0900)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 16 Jul 2024 10:47:44 +0000 (12:47 +0200)
Running qemu-system-aarch64 -M virt -nographic and terminating it will
result in a LeakSanitizer error due to remaining queued CPU work so
free it.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Link: https://lore.kernel.org/r/20240714-cpu-v1-1-19c2f8de2055@daynix.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
cpu-common.c
hw/core/cpu-common.c
include/hw/core/cpu.h

index ce78273af5971dda7ce4e3b1bcb68b3e41e66f91..7ae136f98ca713985b23c204882e98853dd3550d 100644 (file)
@@ -331,6 +331,17 @@ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func,
     queue_work_on_cpu(cpu, wi);
 }
 
+void free_queued_cpu_work(CPUState *cpu)
+{
+    while (!QSIMPLEQ_EMPTY(&cpu->work_list)) {
+        struct qemu_work_item *wi = QSIMPLEQ_FIRST(&cpu->work_list);
+        QSIMPLEQ_REMOVE_HEAD(&cpu->work_list, node);
+        if (wi->free) {
+            g_free(wi);
+        }
+    }
+}
+
 void process_queued_cpu_work(CPUState *cpu)
 {
     struct qemu_work_item *wi;
index b19e1fdacf22380f45dbf1d52145d21b280ff176..d2e3e4570ab782d041d8f6f99a36735001358876 100644 (file)
@@ -281,6 +281,7 @@ static void cpu_common_finalize(Object *obj)
         g_free(cpu->plugin_state);
     }
 #endif
+    free_queued_cpu_work(cpu);
     g_array_free(cpu->gdb_regs, TRUE);
     qemu_lockcnt_destroy(&cpu->in_ioctl_lock);
     qemu_mutex_destroy(&cpu->work_mutex);
index a2c8536943f76f56848ed1e8f6f47571c9a61a17..8e6466c1ddab00d7a09d10e10b4d87f7055e1e5c 100644 (file)
@@ -1000,6 +1000,12 @@ void cpu_resume(CPUState *cpu);
  */
 void cpu_remove_sync(CPUState *cpu);
 
+/**
+ * free_queued_cpu_work() - free all items on CPU work queue
+ * @cpu: The CPU which work queue to free.
+ */
+void free_queued_cpu_work(CPUState *cpu);
+
 /**
  * process_queued_cpu_work() - process all items on CPU work queue
  * @cpu: The CPU which work queue to process.