aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util/mmap-alloc.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
index d713a72ddc..2f55f5e94f 100644
--- a/util/mmap-alloc.c
+++ b/util/mmap-alloc.c
@@ -84,22 +84,20 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared)
return MAP_FAILED;
}
- ptr += offset;
- total -= offset;
-
if (offset > 0) {
- munmap(ptr - offset, offset);
+ munmap(ptr, offset);
}
/*
* Leave a single PROT_NONE page allocated after the RAM block, to serve as
* a guard page guarding against potential buffer overflows.
*/
+ total -= offset;
if (total > size + getpagesize()) {
- munmap(ptr + size + getpagesize(), total - size - getpagesize());
+ munmap(ptr1 + size + getpagesize(), total - size - getpagesize());
}
- return ptr;
+ return ptr1;
}
void qemu_ram_munmap(void *ptr, size_t size)