public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm tools: Free memory and FDs on exit
@ 2011-04-06 16:07 Sasha Levin
  2011-04-06 16:48 ` Pekka Enberg
  0 siblings, 1 reply; 3+ messages in thread
From: Sasha Levin @ 2011-04-06 16:07 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: kvm

Please ignore previous mail, Silly copy&paste mistake on the
signed-off :)

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>
---

 tools/kvm/include/kvm/kvm.h |    1 +
 tools/kvm/kvm.c             |   14 ++++++++++++++
 tools/kvm/main.c            |    4 +++-
 3 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index a1af42f..a099307 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -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);
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 5067b8b..cdc1394 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -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;
diff --git a/tools/kvm/main.c b/tools/kvm/main.c
index 1eeb311..d9c5321 100644
--- a/tools/kvm/main.c
+++ b/tools/kvm/main.c
@@ -220,7 +220,8 @@ int main(int argc, char *argv[])
                }
        }
 exit_kvm:
-       kvm__delete(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);



^ permalink raw reply related	[flat|nested] 3+ messages in thread
* [PATCH] kvm tools: Free memory and FDs on exit
@ 2011-04-06 16:05 Sasha Levin
  0 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2011-04-06 16:05 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: kvm

Following patch adds more cleanup code when exiting.
Close disk image, free msrs array and destroy the timer fd.

Signed-off-by: Justin P. Mattock <justinmattock@gmail.com>
---

 tools/kvm/include/kvm/kvm.h |    1 +
 tools/kvm/kvm.c             |   14 ++++++++++++++
 tools/kvm/main.c            |    4 +++-
 3 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index a1af42f..a099307 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -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);
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 5067b8b..cdc1394 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -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;
diff --git a/tools/kvm/main.c b/tools/kvm/main.c
index 1eeb311..d9c5321 100644
--- a/tools/kvm/main.c
+++ b/tools/kvm/main.c
@@ -220,7 +220,8 @@ int main(int argc, char *argv[])
 		}
 	}
 exit_kvm:
-	kvm__delete(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);


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-04-06 16:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-06 16:07 [PATCH] kvm tools: Free memory and FDs on exit Sasha Levin
2011-04-06 16:48 ` Pekka Enberg
  -- strict thread matches above, loose matches on Subject: below --
2011-04-06 16:05 Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox