More valgrind fixes
authorHannes Reinecke <hare@suse.de>
Tue, 18 Nov 2008 10:33:09 +0000 (11:33 +0100)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Tue, 21 Apr 2009 22:15:35 +0000 (00:15 +0200)
valgrind found some memory which wasn't freed on exit.
Do it now.

Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/config.c
libmultipath/discovery.c
libmultipath/print.c

index cd7ed0f..6039642 100644 (file)
@@ -137,9 +137,6 @@ free_hwe (struct hwentry * hwe)
        if (hwe->revision)
                FREE(hwe->revision);
 
-       if (hwe->selector)
-               FREE(hwe->selector);
-
        if (hwe->getuid)
                FREE(hwe->getuid);
 
@@ -149,6 +146,15 @@ free_hwe (struct hwentry * hwe)
        if (hwe->hwhandler)
                FREE(hwe->hwhandler);
 
+       if (hwe->selector)
+               FREE(hwe->selector);
+
+       if (hwe->checker_name)
+               FREE(hwe->checker_name);
+
+       if (hwe->prio_name)
+               FREE(hwe->prio_name);
+
        if (hwe->bl_product)
                FREE(hwe->bl_product);
 
@@ -404,6 +410,12 @@ free_config (struct config * conf)
        if (conf->checker_name)
                FREE(conf->checker_name);
 
+       if (conf->prio_name)
+               FREE(conf->prio_name);
+
+       if (conf->checker_name)
+               FREE(conf->checker_name);
+
        free_blacklist(conf->blist_devnode);
        free_blacklist(conf->blist_wwid);
        free_blacklist_device(conf->blist_device);
index b29c7b2..a0ae923 100644 (file)
@@ -233,6 +233,7 @@ devt2devname (char *devname, char *devt)
        char block_path[FILE_NAME_SIZE];
        struct stat statbuf;
 
+       memset(block_path, 0, FILE_NAME_SIZE);
        if (sscanf(devt, "%u:%u", &major, &minor) != 2) {
                condlog(0, "Invalid device number %s", devt);
                return 1;
index 986263f..ba77b9c 100644 (file)
@@ -112,19 +112,22 @@ snprint_ro (char * buff, size_t len, struct multipath * mpp)
 static int
 snprint_progress (char * buff, size_t len, int cur, int total)
 {
-       int i = PROGRESS_LEN * cur / total;
-       int j = PROGRESS_LEN - i;
        char * c = buff;
        char * end = buff + len;
 
-       while (i-- > 0) {
-               c += snprintf(c, len, "X");
-               if ((len = (end - c)) <= 1) goto out;
-       }
+       if (total > 0) {
+               int i = PROGRESS_LEN * cur / total;
+               int j = PROGRESS_LEN - i;
+
+               while (i-- > 0) {
+                       c += snprintf(c, len, "X");
+                       if ((len = (end - c)) <= 1) goto out;
+               }
 
-       while (j-- > 0) {
-               c += snprintf(c, len,  ".");
-               if ((len = (end - c)) <= 1) goto out;
+               while (j-- > 0) {
+                       c += snprintf(c, len,  ".");
+                       if ((len = (end - c)) <= 1) goto out;
+               }
        }
 
        c += snprintf(c, len, " %i/%i", cur, total);
@@ -743,6 +746,7 @@ print_multipath_topology (struct multipath * mpp, int verbosity)
 {
        char buff[MAX_LINE_LEN * MAX_LINES] = {};
 
+       memset(&buff[0], 0, MAX_LINE_LEN * MAX_LINES);
        snprint_multipath_topology(&buff[0], MAX_LINE_LEN * MAX_LINES,
                                   mpp, verbosity);
        printf("%s", buff);