From 8b9fb3780ac37d08fb593200f1c43dc5b8dbecf2 Mon Sep 17 00:00:00 2001 From: Yin Fengwei Date: Thu, 28 Jun 2018 17:29:34 +0800 Subject: [PATCH] hv: avoid memory leak in init_msr_emulation If the vcpu->guest_msrs was allocated, don't allocate the memory again to avoid memory leak when init_msr_emulation is called more than once. Signed-off-by: Yin Fengwei Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vmsr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hypervisor/arch/x86/guest/vmsr.c b/hypervisor/arch/x86/guest/vmsr.c index dd0b242a3..b88e7d946 100644 --- a/hypervisor/arch/x86/guest/vmsr.c +++ b/hypervisor/arch/x86/guest/vmsr.c @@ -130,7 +130,9 @@ void init_msr_emulation(struct vcpu *vcpu) exec_vmwrite64(VMX_MSR_BITMAP_FULL, value64); pr_dbg("VMX_MSR_BITMAP: 0x%016llx ", value64); - vcpu->guest_msrs = (uint64_t *)calloc(msrs_count, sizeof(uint64_t)); + if (!vcpu->guest_msrs) + vcpu->guest_msrs = + (uint64_t *)calloc(msrs_count, sizeof(uint64_t)); ASSERT(vcpu->guest_msrs != NULL, ""); memset(vcpu->guest_msrs, 0, msrs_count * sizeof(uint64_t));