Blame SOURCES/0014-multipath-free-vectors-in-configure.patch

68b27c
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
68b27c
From: Benjamin Marzinski <bmarzins@redhat.com>
68b27c
Date: Tue, 11 May 2021 15:25:21 -0500
68b27c
Subject: [PATCH] multipath: free vectors in configure
68b27c
68b27c
configure() can retry multiple times, each time reallocing a maps and
68b27c
paths vector, and leaking the previous ones. Fix this by always freeing
68b27c
the vectors before configure() exits. Found by coverity.
68b27c
68b27c
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
68b27c
---
68b27c
 multipath/main.c | 7 ++++++-
68b27c
 1 file changed, 6 insertions(+), 1 deletion(-)
68b27c
68b27c
diff --git a/multipath/main.c b/multipath/main.c
68b27c
index f618550d..9fe53dcd 100644
68b27c
--- a/multipath/main.c
68b27c
+++ b/multipath/main.c
68b27c
@@ -512,7 +512,6 @@ configure (struct config *conf, enum mpath_cmds cmd,
68b27c
 	 */
68b27c
 	curmp = vector_alloc();
68b27c
 	pathvec = vector_alloc();
68b27c
-	atexit(cleanup_vecs);
68b27c
 
68b27c
 	if (!curmp || !pathvec) {
68b27c
 		condlog(0, "can not allocate memory");
68b27c
@@ -624,6 +623,11 @@ out:
68b27c
 	if (refwwid)
68b27c
 		FREE(refwwid);
68b27c
 
68b27c
+	free_multipathvec(curmp, KEEP_PATHS);
68b27c
+	vecs.mpvec = NULL;
68b27c
+	free_pathvec(pathvec, FREE_PATHS);
68b27c
+	vecs.pathvec = NULL;
68b27c
+
68b27c
 	return r;
68b27c
 }
68b27c
 
68b27c
@@ -869,6 +873,7 @@ main (int argc, char *argv[])
68b27c
 	conf = get_multipath_config();
68b27c
 	conf->retrigger_tries = 0;
68b27c
 	conf->force_sync = 1;
68b27c
+	atexit(cleanup_vecs);
68b27c
 	while ((arg = getopt(argc, argv, ":aAdDcChl::eFfM:v:p:b:BrR:itTquUwW")) != EOF ) {
68b27c
 		switch(arg) {
68b27c
 		case 1: printf("optarg : %s\n",optarg);