diff mbox series

[4/4] i386/cpu: Free env->xsave_buf in x86_cpu_unrealizefn()

Message ID 20220126142946.667782-5-mark.kanda@oracle.com (mailing list archive)
State New, archived
Headers show
Series vCPU hotunplug related memory leaks | expand

Commit Message

Mark Kanda Jan. 26, 2022, 2:29 p.m. UTC
vCPU hotunplug related leak reported by Valgrind:

==377357== 4,096 bytes in 1 blocks are definitely lost in loss record 8,354 of 8,471
==377357==    at 0x4C3B15F: memalign (vg_replace_malloc.c:1265)
==377357==    by 0x4C3B288: posix_memalign (vg_replace_malloc.c:1429)
==377357==    by 0xAA4773: qemu_try_memalign (oslib-posix.c:222)
==377357==    by 0xAA47E5: qemu_memalign (oslib-posix.c:238)
==377357==    by 0x6C403D: kvm_arch_init_vcpu (kvm.c:1986)
==377357==    by 0x8AEB01: kvm_init_vcpu (kvm-all.c:516)
==377357==    by 0x8B59EA: kvm_vcpu_thread_fn (kvm-accel-ops.c:40)
==377357==    by 0xAA72F0: qemu_thread_start (qemu-thread-posix.c:556)
==377357==    by 0x8EE8159: start_thread (in /usr/lib64/libpthread-2.28.so)
==377357==    by 0x91FCDD2: clone (in /usr/lib64/libc-2.28.so)

Signed-off-by: Mark Kanda <mark.kanda@oracle.com>
---
 target/i386/cpu.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index aa9e636800..33405d245d 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6487,6 +6487,7 @@  static void x86_cpu_unrealizefn(DeviceState *dev)
 {
     X86CPU *cpu = X86_CPU(dev);
     X86CPUClass *xcc = X86_CPU_GET_CLASS(dev);
+    CPUX86State *env = &cpu->env;
 
 #ifndef CONFIG_USER_ONLY
     cpu_remove_sync(CPU(dev));
@@ -6499,6 +6500,7 @@  static void x86_cpu_unrealizefn(DeviceState *dev)
     }
 
     xcc->parent_unrealize(dev);
+    g_free(env->xsave_buf);
 }
 
 typedef struct BitProperty {