[dm-devel] [PATCH 02/28] libmultipath: fix memory leak in process_config_dir()

Martin Wilck mwilck at suse.com
Fri Jun 8 10:20:15 UTC 2018


Signed-off-by: Martin Wilck <mwilck at suse.com>
---
 libmultipath/config.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/libmultipath/config.c b/libmultipath/config.c
index 085a3e12..8769441c 100644
--- a/libmultipath/config.c
+++ b/libmultipath/config.c
@@ -551,6 +551,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
@@ -574,7 +579,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;
@@ -586,6 +593,7 @@ process_config_dir(struct config *conf, vector keywords, char *dir)
 			factorize_hwtable(conf->hwtable, old_hwtable_size);
 
 	}
+	pthread_cleanup_pop(1);
 }
 
 struct config *
-- 
2.17.0




More information about the dm-devel mailing list