[dm-devel] [PATCH 4/5] multipath: free vectors in configure
Benjamin Marzinski
bmarzins at redhat.com
Tue May 11 23:22:03 UTC 2021
configure() can retry multiple times, each time reallocing a maps and
paths vector, and leaking the previous ones. Fix this by always freeing
the vectors before configure() exits. Found by coverity.
Signed-off-by: Benjamin Marzinski <bmarzins at redhat.com>
---
multipath/main.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/multipath/main.c b/multipath/main.c
index ef89c7cf..25c5dbfd 100644
--- a/multipath/main.c
+++ b/multipath/main.c
@@ -466,7 +466,6 @@ configure (struct config *conf, enum mpath_cmds cmd,
*/
curmp = vector_alloc();
pathvec = vector_alloc();
- atexit(cleanup_vecs);
if (!curmp || !pathvec) {
condlog(0, "can not allocate memory");
@@ -578,6 +577,11 @@ out:
if (refwwid)
FREE(refwwid);
+ free_multipathvec(curmp, KEEP_PATHS);
+ vecs.mpvec = NULL;
+ free_pathvec(pathvec, FREE_PATHS);
+ vecs.pathvec = NULL;
+
return r;
}
@@ -1053,6 +1057,7 @@ main (int argc, char *argv[])
r = dm_flush_maps(1, retries) ? RTVL_FAIL : RTVL_OK;
goto out;
}
+ atexit(cleanup_vecs);
while ((r = configure(conf, cmd, dev_type, dev)) == RTVL_RETRY)
condlog(3, "restart multipath configuration process");
--
2.17.2
More information about the dm-devel
mailing list