[Spice-devel] [PATCH 15/18] Avoid to call munmap with invalid size
Frediano Ziglio
fziglio at redhat.com
Mon Sep 26 08:12:48 UTC 2016
This could have happened if mremap failed.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
tools/reds_stat.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/reds_stat.c b/tools/reds_stat.c
index 945659e..d7d82ec 100644
--- a/tools/reds_stat.c
+++ b/tools/reds_stat.c
@@ -66,7 +66,7 @@ int main(int argc, char **argv)
pid_t kvm_pid;
uint32_t num_of_nodes = 0;
size_t shm_size;
- size_t shm_old_size;
+ size_t shm_new_size;
int shm_name_len;
int ret = -1;
int fd;
@@ -105,13 +105,13 @@ int main(int argc, char **argv)
printf("spice statistics\n\n");
if (num_of_nodes != reds_stat->num_of_nodes) {
num_of_nodes = reds_stat->num_of_nodes;
- shm_old_size = shm_size;
- shm_size = sizeof(SpiceStat) + num_of_nodes * sizeof(SpiceStatNode);
- reds_stat = mremap(reds_stat, shm_old_size, shm_size, MREMAP_MAYMOVE);
+ shm_new_size = sizeof(SpiceStat) + num_of_nodes * sizeof(SpiceStatNode);
+ reds_stat = mremap(reds_stat, shm_size, shm_new_size, MREMAP_MAYMOVE);
if (reds_stat == (SpiceStat *)MAP_FAILED) {
perror("mremap");
goto error;
}
+ shm_size = shm_new_size;
values = (uint64_t *)realloc(values, num_of_nodes * sizeof(uint64_t));
if (values == NULL) {
perror("realloc");
--
2.7.4
More information about the Spice-devel
mailing list