mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-09-05 13:11:44 +00:00
kvm tools: Free memory and FDs on exit
Following patch adds more cleanup code when exiting. Close disk image, free msrs array and destroy the timer fd. Signed-off-by: Sasha Levin <levinsasha928@gmail.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
@@ -43,6 +43,7 @@ bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,
|
||||
void kvm__reset_vcpu(struct kvm *self);
|
||||
void kvm__setup_bios(struct kvm *self);
|
||||
void kvm__start_timer(struct kvm *self);
|
||||
void kvm__stop_timer(struct kvm *self);
|
||||
void kvm__run(struct kvm *self);
|
||||
void kvm__irq_line(struct kvm *self, int irq, int level);
|
||||
bool kvm__emulate_io(struct kvm *self, uint16_t port, void *data, int direction, int size, uint32_t count);
|
||||
|
||||
@@ -105,6 +105,11 @@ static struct kvm *kvm__new(void)
|
||||
|
||||
void kvm__delete(struct kvm *self)
|
||||
{
|
||||
kvm__stop_timer(self);
|
||||
|
||||
if (self->msrs)
|
||||
free(self->msrs);
|
||||
|
||||
free(self->ram_start);
|
||||
free(self);
|
||||
}
|
||||
@@ -612,6 +617,15 @@ void kvm__start_timer(struct kvm *self)
|
||||
die("timer_settime()");
|
||||
}
|
||||
|
||||
void kvm__stop_timer(struct kvm *self)
|
||||
{
|
||||
if (self->timerid)
|
||||
if (timer_delete(self->timerid) < 0)
|
||||
die("timer_delete()");
|
||||
|
||||
self->timerid = 0;
|
||||
}
|
||||
|
||||
void kvm__run(struct kvm *self)
|
||||
{
|
||||
int err;
|
||||
|
||||
@@ -220,6 +220,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
exit_kvm:
|
||||
disk_image__close(kvm->disk_image);
|
||||
kvm__delete(kvm);
|
||||
|
||||
return 0;
|
||||
@@ -230,6 +231,7 @@ panic_kvm:
|
||||
if (kvm->kvm_run->exit_reason == KVM_EXIT_UNKNOWN)
|
||||
fprintf(stderr, "KVM exit code: 0x%" PRIu64 "\n",
|
||||
kvm->kvm_run->hw.hardware_exit_reason);
|
||||
disk_image__close(kvm->disk_image);
|
||||
kvm__show_registers(kvm);
|
||||
kvm__show_code(kvm);
|
||||
kvm__show_page_tables(kvm);
|
||||
|
||||
Reference in New Issue
Block a user