[Spice-commits] tools/reds_stat.c

Frediano Ziglio fziglio at kemper.freedesktop.org
Mon Sep 26 09:22:28 UTC 2016


 tools/reds_stat.c |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

New commits:
commit 03ff0dcef98827dc2eca4858244e72455cf8f5ef
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Mon Sep 26 09:05:12 2016 +0100

    Make error simpler in reds_stat
    
    There's no reason for so hard optimisations so avoid
    having to maintain multiple labels.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Pavel Grunt <pgrunt at redhat.com>

diff --git a/tools/reds_stat.c b/tools/reds_stat.c
index 5e9705c..9aca1ad 100644
--- a/tools/reds_stat.c
+++ b/tools/reds_stat.c
@@ -30,7 +30,7 @@
 #define VALUE_TABS 7
 #define INVALID_STAT_REF (~(uint32_t)0)
 
-static SpiceStat *reds_stat = NULL;
+static SpiceStat *reds_stat = (SpiceStat *)MAP_FAILED;
 static uint64_t *values = NULL;
 
 void print_stat_tree(int32_t node_index, int depth)
@@ -87,15 +87,15 @@ int main(int argc, char **argv)
     reds_stat = (SpiceStat *)mmap(NULL, shm_size, PROT_READ, MAP_SHARED, fd, 0);
     if (reds_stat == (SpiceStat *)MAP_FAILED) {
         perror("mmap");
-        goto error1;
+        goto error;
     }
     if (reds_stat->magic != SPICE_STAT_MAGIC) {
         printf("bad magic %u\n", reds_stat->magic);
-        goto error2;
+        goto error;
     }
     if (reds_stat->version != SPICE_STAT_VERSION) {
         printf("bad version %u\n", reds_stat->version);
-        goto error2;
+        goto error;
     }
     while (1) {
         system("clear");
@@ -107,12 +107,12 @@ int main(int argc, char **argv)
             reds_stat = mremap(reds_stat, shm_old_size, shm_size, MREMAP_MAYMOVE);
             if (reds_stat == (SpiceStat *)MAP_FAILED) {
                 perror("mremap");
-                goto error3;
+                goto error;
             }
             values = (uint64_t *)realloc(values, num_of_nodes * sizeof(uint64_t));
             if (values == NULL) {
                 perror("realloc");
-                goto error3;
+                goto error;
             }
             memset(values, 0, num_of_nodes * sizeof(uint64_t));
         }
@@ -121,11 +121,11 @@ int main(int argc, char **argv)
     }
     ret = 0;
 
-error3:
+error:
     free(values);
-error2:
-    munmap(reds_stat, shm_size);
-error1:
+    if (reds_stat != (SpiceStat *)MAP_FAILED) {
+        munmap(reds_stat, shm_size);
+    }
     shm_unlink(shm_name);
     free(shm_name);
     return ret;


More information about the Spice-commits mailing list