diff mbox

kvm tools: Fix attempt to free mmaped memory

Message ID 1308309196-4757-1-git-send-email-levinsasha928@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sasha Levin June 17, 2011, 11:13 a.m. UTC
Framebuffer memory which was mmap() is being free() at the shutdown
of the guest, leading to glibc errors.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/framebuffer.c             |    3 ++-
 tools/kvm/hw/vesa.c                 |    1 +
 tools/kvm/include/kvm/framebuffer.h |    1 +
 3 files changed, 4 insertions(+), 1 deletions(-)
diff mbox

Patch

diff --git a/tools/kvm/framebuffer.c b/tools/kvm/framebuffer.c
index 1e35496..b6eb1ac 100644
--- a/tools/kvm/framebuffer.c
+++ b/tools/kvm/framebuffer.c
@@ -3,6 +3,7 @@ 
 #include <linux/kernel.h>
 #include <linux/list.h>
 #include <stdlib.h>
+#include <sys/mman.h>
 
 static LIST_HEAD(framebuffers);
 
@@ -62,6 +63,6 @@  void fb__stop(void)
 	struct framebuffer *fb;
 
 	list_for_each_entry(fb, &framebuffers, node) {
-		free(fb->mem);
+		munmap(fb->mem, fb->mem_size);
 	}
 }
diff --git a/tools/kvm/hw/vesa.c b/tools/kvm/hw/vesa.c
index 71322fc..032e630 100644
--- a/tools/kvm/hw/vesa.c
+++ b/tools/kvm/hw/vesa.c
@@ -70,6 +70,7 @@  struct framebuffer *vesa__init(struct kvm *kvm)
 		.depth			= VESA_BPP,
 		.mem			= mem,
 		.mem_addr		= VESA_MEM_ADDR,
+		.mem_size		= VESA_MEM_SIZE,
 	};
 	return fb__register(&vesafb);
 }
diff --git a/tools/kvm/include/kvm/framebuffer.h b/tools/kvm/include/kvm/framebuffer.h
index d28dadb..b66d0ba 100644
--- a/tools/kvm/include/kvm/framebuffer.h
+++ b/tools/kvm/include/kvm/framebuffer.h
@@ -20,6 +20,7 @@  struct framebuffer {
 	u8				depth;
 	char				*mem;
 	u64				mem_addr;
+	u64				mem_size;
 
 	unsigned long			nr_targets;
 	struct fb_target_operations	*targets[FB_MAX_TARGETS];