i386/hvf: Fixes startup memory leak (vmcs caps)
authorPhil Dennis-Jordan <phil@philjordan.eu>
Tue, 5 Nov 2024 15:57:58 +0000 (16:57 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Sat, 9 Nov 2024 07:34:07 +0000 (08:34 +0100)
The hvf_caps data structure only exists once as part of the hvf accelerator
state, but it is initialised during vCPU initialisation. This change therefore
adds a check to ensure memory for it is only allocated once.

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
Link: https://lore.kernel.org/r/20241105155800.5461-4-phil@philjordan.eu
Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
target/i386/hvf/hvf.c

index 68dc5d9cf755521b6b110f71c835ff7a709d0e4f..8527bce6eeffa95a7a9f91325cf5d120abb7d51e 100644 (file)
@@ -239,7 +239,9 @@ int hvf_arch_init_vcpu(CPUState *cpu)
     init_emu();
     init_decoder();
 
-    hvf_state->hvf_caps = g_new0(struct hvf_vcpu_caps, 1);
+    if (hvf_state->hvf_caps == NULL) {
+        hvf_state->hvf_caps = g_new0(struct hvf_vcpu_caps, 1);
+    }
     env->hvf_mmio_buf = g_new(char, 4096);
 
     if (x86cpu->vmware_cpuid_freq) {