[dm-devel] [PATCH 04/39] libmultipath: free pathgroup in group_by_prio()

Hannes Reinecke hare at suse.de
Thu Jun 16 09:47:10 UTC 2016


If we encounter an error when storing the pathgroup or paths
the pathgroup is never deallocated.
Found by coverity.

Signed-off-by: Hannes Reinecke <hare at suse.com>
---
 libmultipath/pgpolicies.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/libmultipath/pgpolicies.c b/libmultipath/pgpolicies.c
index 2981d51..f440441 100644
--- a/libmultipath/pgpolicies.c
+++ b/libmultipath/pgpolicies.c
@@ -341,8 +341,10 @@ group_by_prio (struct multipath * mp)
 		if (!pgp)
 			goto out;
 
-		if (store_path(pgp->paths, VECTOR_SLOT(mp->paths, 0)))
-				goto out;
+		if (store_path(pgp->paths, VECTOR_SLOT(mp->paths, 0))) {
+			free_pathgroup(pgp, KEEP_PATHS);
+			goto out;
+		}
 
 		vector_del_slot(mp->paths, 0);
 
@@ -350,11 +352,15 @@ group_by_prio (struct multipath * mp)
 		 * Store the new path group into the vector.
 		 */
 		if (i < VECTOR_SIZE(mp->pg)) {
-			if (!vector_insert_slot(mp->pg, i, pgp))
+			if (!vector_insert_slot(mp->pg, i, pgp)) {
+				free_pathgroup(pgp, KEEP_PATHS);
 				goto out;
+			}
 		} else {
-			if (store_pathgroup(mp->pg, pgp))
+			if (store_pathgroup(mp->pg, pgp)) {
+				free_pathgroup(pgp, KEEP_PATHS);
 				goto out;
+			}
 		}
 
 		/*
-- 
2.6.6




More information about the dm-devel mailing list