Skip to content

Commit 8b9fb37

Browse files
fyin1lijinxia
authored andcommitted
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>
1 parent 57c217b commit 8b9fb37

File tree

1 file changed

+3
-1
lines changed
  • hypervisor/arch/x86/guest

1 file changed

+3
-1
lines changed

hypervisor/arch/x86/guest/vmsr.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ void init_msr_emulation(struct vcpu *vcpu)
130130
exec_vmwrite64(VMX_MSR_BITMAP_FULL, value64);
131131
pr_dbg("VMX_MSR_BITMAP: 0x%016llx ", value64);
132132

133-
vcpu->guest_msrs = (uint64_t *)calloc(msrs_count, sizeof(uint64_t));
133+
if (!vcpu->guest_msrs)
134+
vcpu->guest_msrs =
135+
(uint64_t *)calloc(msrs_count, sizeof(uint64_t));
134136

135137
ASSERT(vcpu->guest_msrs != NULL, "");
136138
memset(vcpu->guest_msrs, 0, msrs_count * sizeof(uint64_t));

0 commit comments

Comments
 (0)