libmultipath: fix memory leak in process_config_dir()
authorMartin Wilck <mwilck@suse.com>
Fri, 8 Jun 2018 10:20:15 +0000 (12:20 +0200)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Thu, 21 Jun 2018 07:38:41 +0000 (09:38 +0200)
Signed-off-by: Martin Wilck <mwilck@suse.com>
libmultipath/config.c

index 5872927..d6e1ca9 100644 (file)
@@ -552,6 +552,11 @@ free_config (struct config * conf)
        FREE(conf);
 }
 
+static void free_namelist(void *nl)
+{
+       free(nl);
+}
+
 /* if multipath fails to process the config directory, it should continue,
  * with just a warning message */
 static void
@@ -575,7 +580,9 @@ process_config_dir(struct config *conf, vector keywords, char *dir)
                        condlog(0, "couldn't open configuration dir '%s': %s",
                                dir, strerror(errno));
                return;
-       }
+       } else if (n == 0)
+               return;
+       pthread_cleanup_push(free_namelist, namelist);
        for (i = 0; i < n; i++) {
                if (!strstr(namelist[i]->d_name, ".conf"))
                        continue;
@@ -587,6 +594,7 @@ process_config_dir(struct config *conf, vector keywords, char *dir)
                        factorize_hwtable(conf->hwtable, old_hwtable_size);
 
        }
+       pthread_cleanup_pop(1);
 }
 
 struct config *