libmultipath: free pp if store_path fails in disassemble_map
PATCH 1/1 libmultipath: free pp if store_path fails in disassemble_map
In disassemble_map func, one pp will be allocated and stored in pathvec (only in client mode) and 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.
--- libmultipath/dmparser.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
libmultipath/dmparser.c +13 -2
@@ -142,6 +142,7 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,int def_minio =0 ;struct path * pp;struct pathgroup * pgp; +int pp_need_free_flag =0 ; p = params;
@@ -293,6 +294,7 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,char devname[FILE_NAME_SIZE ]; pp =NULL ; + pp_need_free_flag =0 ; p +=get_word (p, &word);if (!word)
@@ -323,9 +325,15 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,strncpy (pp->wwid, mpp->wwid,WWID_SIZE -1 ); } + +if (is_daemon) + pp_need_free_flag =1 ; +/* Only call this in multipath client mode */ -if (!is_daemon &&store_path (pathvec, pp)) +if (!is_daemon &&store_path (pathvec, pp)) { +free_path (pp); goto out1; + } }else {if (!strlen (pp->wwid) &&strlen (mpp->wwid))
@@ -334,8 +342,11 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, }FREE (word); -if (store_path (pgp->paths, pp)) +if (store_path (pgp->paths, pp)) { +if (pp_need_free_flag) +free_path (pp); goto out; + }/* * Update wwid for multipaths which are not setup
Signature · 1 line
2.24.0.windows.2
Quoted 6 lines · Zhiqiang Liu
In
disassemble_mapfunc, one pp will be allocated and stored in pathvec (only in client mode) andpgp->paths. However, ifstore_pathfails, pp will not be freed, then memory leak problem occurs.Here, we will call
free_pathto free pp whenstore_pathfails.
However, this will need to get reworked on top of Martin's patches (or incorporated into his next verion patchset).
-Ben
Quoted 59 lines
Signed-off-by Zhiqiang Liu <[email protected]>Signed-off-by lixiaokeng <[email protected]>--- libmultipath/dmparser.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)libmultipath/dmparser.c +13
-2@@ -142,6 +142,7 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,int def_minio =0 ;struct path * pp;struct pathgroup * pgp; +int pp_need_free_flag =0 ; p = params;@@ -293,6 +294,7 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,char devname[FILE_NAME_SIZE ]; pp =NULL ; + pp_need_free_flag =0 ; p +=get_word (p, &word);if (!word)@@ -323,9 +325,15 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,strncpy (pp->wwid, mpp->wwid,WWID_SIZE -1 ); } + +if (is_daemon) + pp_need_free_flag =1 ; +/* Only call this in multipath client mode */ -if (!is_daemon &&store_path (pathvec, pp)) +if (!is_daemon &&store_path (pathvec, pp)) { +free_path (pp); goto out1; + } }else {if (!strlen (pp->wwid) &&strlen (mpp->wwid))@@ -334,8 +342,11 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, }FREE (word); -if (store_path (pgp->paths, pp)) +if (store_path (pgp->paths, pp)) { +if (pp_need_free_flag) +free_path (pp); goto out; + }/* * Update wwid for multipaths which are not setup Signature · 1 line
2.24.0.windows.2
Quoted 5 lines · Benjamin Marzinski
Quoted 4 lines · Zhiqiang Liu
In
disassemble_mapfunc, one pp will be allocated and stored in pathvec (only in client mode) andpgp->paths. However, ifstore_pathfails, pp will not be freed, then memory leak problem occurs.
Quoted 8 lines
Quoted 2 lines
Here, we will call
free_pathto free pp whenstore_pathfails.Reviewed-by Benjamin Marzinski <[email protected]>However, this will need to get reworked on top of Martin's patches (or incorporated into his next verion patchset).
Thanks for your suggestion.
Which branch should I choose to modify my patch?
Quoted 65 lines
-Ben
Quoted 59 lines
Signed-off-by Zhiqiang Liu <[email protected]>Signed-off-by lixiaokeng <[email protected]>--- libmultipath/dmparser.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)libmultipath/dmparser.c +13
-2@@ -142,6 +142,7 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,int def_minio =0 ;struct path * pp;struct pathgroup * pgp; +int pp_need_free_flag =0 ; p = params;@@ -293,6 +294,7 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,char devname[FILE_NAME_SIZE ]; pp =NULL ; + pp_need_free_flag =0 ; p +=get_word (p, &word);if (!word)@@ -323,9 +325,15 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,strncpy (pp->wwid, mpp->wwid,WWID_SIZE -1 ); } + +if (is_daemon) + pp_need_free_flag =1 ; +/* Only call this in multipath client mode */ -if (!is_daemon &&store_path (pathvec, pp)) +if (!is_daemon &&store_path (pathvec, pp)) { +free_path (pp); goto out1; + } }else {if (!strlen (pp->wwid) &&strlen (mpp->wwid))@@ -334,8 +342,11 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, }FREE (word); -if (store_path (pgp->paths, pp)) +if (store_path (pgp->paths, pp)) { +if (pp_need_free_flag) +free_path (pp); goto out; + }/* * Update wwid for multipaths which are not setup Signature · 1 line
2.24.0.windows.2.
Benjamin Marzinski
maintainerQuoted 11 lines · Zhiqiang Liu
Quoted 8 lines · Benjamin Marzinski
Quoted 6 lines · Zhiqiang Liu
In
disassemble_mapfunc, one pp will be allocated and stored in pathvec (only in client mode) andpgp->paths. However, ifstore_pathfails, pp will not be freed, then memory leak problem occurs.Here, we will call
free_pathto free pp whenstore_pathfails.
Quoted 8 lines
Quoted 5 lines
Reviewed-by Benjamin Marzinski <[email protected]>However, this will need to get reworked on top of Martin's patches (or incorporated into his next verion patchset).
Thanks for your suggestion.
Which branch should I choose to modify my patch?
Martin's latest set of commits is available here:
https://github.com/mwilck/multipath-tools/tree/ups/submit-2007
Quoted 67 lines
Quoted 67 lines
-Ben
Quoted 59 lines
Signed-off-by Zhiqiang Liu <[email protected]>Signed-off-by lixiaokeng <[email protected]>--- libmultipath/dmparser.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)libmultipath/dmparser.c +13
-2@@ -142,6 +142,7 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,int def_minio =0 ;struct path * pp;struct pathgroup * pgp; +int pp_need_free_flag =0 ; p = params;@@ -293,6 +294,7 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,char devname[FILE_NAME_SIZE ]; pp =NULL ; + pp_need_free_flag =0 ; p +=get_word (p, &word);if (!word)@@ -323,9 +325,15 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,strncpy (pp->wwid, mpp->wwid,WWID_SIZE -1 ); } + +if (is_daemon) + pp_need_free_flag =1 ; +/* Only call this in multipath client mode */ -if (!is_daemon &&store_path (pathvec, pp)) +if (!is_daemon &&store_path (pathvec, pp)) { +free_path (pp); goto out1; + } }else {if (!strlen (pp->wwid) &&strlen (mpp->wwid))@@ -334,8 +342,11 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, }FREE (word); -if (store_path (pgp->paths, pp)) +if (store_path (pgp->paths, pp)) { +if (pp_need_free_flag) +free_path (pp); goto out; + }/* * Update wwid for multipaths which are not setup Signature · 1 line
2.24.0.windows.2.
Quoted 18 lines · Benjamin Marzinski
Quoted 17 lines · Zhiqiang Liu
Quoted 13 lines · Benjamin Marzinski
Quoted 6 lines · Zhiqiang Liu
In
disassemble_mapfunc, one pp will be allocated and stored in pathvec (only in client mode) andpgp->paths. However, ifstore_pathfails, pp will not be freed, then memory leak problem occurs.Here, we will call
free_pathto free pp whenstore_pathfails.Reviewed-by Benjamin Marzinski <[email protected]>However, this will need to get reworked on top of Martin's patches (or incorporated into his next verion patchset).
Quoted 8 lines
Quoted 2 lines
Thanks for your suggestion.
Which branch should I choose to modify my patch?Martin's latest set of commits is available here:
https://github.com/mwilck/multipath-tools/tree/ups/submit-2007Quoted 2 lines
Thanks for your patience.
I will send the V2 patch based on the branch: ups/submit-2007.
Quoted 69 lines
Quoted 56 lines
Quoted 56 lines
-Ben
Quoted 54 lines
Signed-off-by Zhiqiang Liu <[email protected]>Signed-off-by lixiaokeng <[email protected]>--- libmultipath/dmparser.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)libmultipath/dmparser.c +13
-2@@ -142,6 +142,7 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,int def_minio =0 ;struct path * pp;struct pathgroup * pgp; +int pp_need_free_flag =0 ; p = params;@@ -293,6 +294,7 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,char devname[FILE_NAME_SIZE ]; pp =NULL ; + pp_need_free_flag =0 ; p +=get_word (p, &word);if (!word)@@ -323,9 +325,15 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,strncpy (pp->wwid, mpp->wwid,WWID_SIZE -1 ); } + +if (is_daemon) + pp_need_free_flag =1 ; +/* Only call this in multipath client mode */ -if (!is_daemon &&store_path (pathvec, pp)) +if (!is_daemon &&store_path (pathvec, pp)) { +free_path (pp); goto out1; + } }else {if (!strlen (pp->wwid) &&strlen (mpp->wwid))@@ -334,8 +342,11 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, }FREE (word); -if (store_path (pgp->paths, pp)) +if (store_path (pgp->paths, pp)) { +if (pp_need_free_flag) +free_path (pp); goto out; + }Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
libmultipath/dmparser.c +0
-0/* * Update wwid for multipaths which are not setup Signature · 1 line
2.24.0.windows.2.
.