All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] libmultipath: free pp if store_path fails in disassemble_map
@ 2020-07-24  1:40 Zhiqiang Liu
  2020-07-24 16:34 ` Benjamin Marzinski
  2020-08-10 12:20 ` Martin Wilck
  0 siblings, 2 replies; 6+ messages in thread
From: Zhiqiang Liu @ 2020-07-24  1:40 UTC (permalink / raw)
  To: Martin Wilck, Benjamin Marzinski, christophe.varoqui, Zdenek Kabelac
  Cc: linfeilong, yanxiaodan, dm-devel

In disassemble_map func, one pp will be allocated and stored in
pgp->paths. However, if store_path fails, pp will not be freed,
then memory leak problem occurs.

Here, we will call free_path to free pp when store_path fails.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: lixiaokeng <lixiaokeng@huawei.com>
---
V1->V2: update based on ups/submit-2007 branch.

 libmultipath/dmparser.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libmultipath/dmparser.c b/libmultipath/dmparser.c
index b9858fa5..8a0501ba 100644
--- a/libmultipath/dmparser.c
+++ b/libmultipath/dmparser.c
@@ -143,6 +143,7 @@ int disassemble_map(const struct _vector *pathvec,
 	int def_minio = 0;
 	struct path * pp;
 	struct pathgroup * pgp;
+	int pp_alloc_flag = 0;

 	assert(pathvec != NULL);
 	p = params;
@@ -292,6 +293,7 @@ int disassemble_map(const struct _vector *pathvec,

 		for (j = 0; j < num_paths; j++) {
 			pp = NULL;
+			pp_alloc_flag = 0;
 			p += get_word(p, &word);

 			if (!word)
@@ -304,13 +306,16 @@ int disassemble_map(const struct _vector *pathvec,

 				if (!pp)
 					goto out1;
-
+				pp_alloc_flag = 1;
 				strlcpy(pp->dev_t, word, BLK_DEV_SIZE);
 			}
 			FREE(word);

-			if (store_path(pgp->paths, pp))
+			if (store_path(pgp->paths, pp)) {
+				if (pp_alloc_flag)
+					free_path(pp);
 				goto out;
+			}

 			pgp->id ^= (long)pp;
 			pp->pgindex = i + 1;
-- 
2.24.0.windows.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-08-10 19:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-24  1:40 [PATCH V2] libmultipath: free pp if store_path fails in disassemble_map Zhiqiang Liu
2020-07-24 16:34 ` Benjamin Marzinski
2020-08-10 12:20 ` Martin Wilck
2020-08-10 12:37   ` Zhiqiang Liu
2020-08-10 19:07   ` Benjamin Marzinski
2020-08-10 19:35     ` Martin Wilck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.