diff mbox series

[3/5] i386/hvf: Fixes startup memory leak (vmcs caps)

Message ID 20241105155800.5461-4-phil@philjordan.eu (mailing list archive)
State New
Headers show
Series i386/hvf: x2apic support and some small fixes | expand

Commit Message

Phil Dennis-Jordan Nov. 5, 2024, 3:57 p.m. UTC
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>
---
 target/i386/hvf/hvf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Roman Bolshakov Nov. 6, 2024, 2:03 p.m. UTC | #1
On Tue, Nov 05, 2024 at 04:57:58PM +0100, Phil Dennis-Jordan wrote:
> 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.
> 

Looks good,

Reviewed-by: Roman Bolshakov <rbolshakov@ddn.com>

Regards,
Roman
diff mbox series

Patch

diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 68dc5d9cf75..8527bce6eef 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -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) {