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 <fengwei.yin@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Yin Fengwei 2018-06-28 17:29:34 +08:00 committed by lijinxia
parent 57c217bf26
commit 8b9fb3780a
1 changed files with 3 additions and 1 deletions

View File

@ -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));