libmultipath: free pgp if add_pathgroup fails in disassemble_map func
PATCH 1/1 libmultipath: free pgp if add_pathgroup fails in disassemble_map func
In disassemble_map func, pgp will be added to mpp->pg by calling add_pathgroup after allocing a pathgroup (pgp) successfully. However, if add_pathgroup fails, the pgp is actually not inserted into mpp->pg. So, calling free_pgvec(mpp->pg) cannot free the pgp, then memory leak problem occurs.
disassemble_map:
-> pgp = alloc_pathgroup()
-> if add_pathgroup(mpp, pgp) fails
-> goto out
out:free_pgvec(mpp->pg, KEEP_PATHS);
Here, we will call free_pathgroup(pgp) before going to out tag.
--- libmultipath/dmparser.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
libmultipath/dmparser.c +3 -1
@@ -268,8 +268,10 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,if (!pgp) goto out; -if (add_pathgroup (mpp, pgp)) +if (add_pathgroup (mpp, pgp)) { +free_pathgroup (pgp,KEEP_PATHS ); goto out; + } p +=get_word (p, &word);
Signature · 1 line
2.24.0.windows.2
Quoted 6 lines · Zhiqiang Liu
In
disassemble_mapfunc, pgp will be added tompp->pgby callingadd_pathgroupafter allocing a pathgroup (pgp) successfully. However, ifadd_pathgroupfails, the pgp is actually not inserted intompp->pg. So, callingfree_pgvec(mpp->pg)cannot free the pgp, then memory leak problem occurs.
Quoted 9 lines
disassemble_map:
-> pgp =alloc_pathgroup()
-> ifadd_pathgroup(mpp, pgp)fails-> goto outout:
free_pgvec(mpp->pg, KEEP_PATHS);Here, we will call
free_pathgroup(pgp)before going to out tag.
Quoted 25 lines
Signed-off-by Zhiqiang Liu <[email protected]>Signed-off-by lixiaokeng <[email protected]>--- libmultipath/dmparser.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)libmultipath/dmparser.c +3
-1@@ -268,8 +268,10 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,if (!pgp) goto out; -if (add_pathgroup (mpp, pgp)) +if (add_pathgroup (mpp, pgp)) { +free_pathgroup (pgp,KEEP_PATHS ); goto out; + } p +=get_word (p, &word);Signature · 1 line
2.24.0.windows.2
Thanks for your review.
Quoted 48 lines · Benjamin Marzinski
Quoted 6 lines · Zhiqiang Liu
In
disassemble_mapfunc, pgp will be added tompp->pgby callingadd_pathgroupafter allocing a pathgroup (pgp) successfully. However, ifadd_pathgroupfails, the pgp is actually not inserted intompp->pg. So, callingfree_pgvec(mpp->pg)cannot free the pgp, then memory leak problem occurs.Quoted 9 lines
disassemble_map:
-> pgp =alloc_pathgroup()
-> ifadd_pathgroup(mpp, pgp)fails-> goto outout:
free_pgvec(mpp->pg, KEEP_PATHS);Here, we will call
free_pathgroup(pgp)before going to out tag.Reviewed-by Benjamin Marzinski <[email protected]>Quoted 25 lines
Signed-off-by Zhiqiang Liu <[email protected]>Signed-off-by lixiaokeng <[email protected]>--- libmultipath/dmparser.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)libmultipath/dmparser.c +3
-1@@ -268,8 +268,10 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,if (!pgp) goto out; -if (add_pathgroup (mpp, pgp)) +if (add_pathgroup (mpp, pgp)) { +free_pathgroup (pgp,KEEP_PATHS ); goto out; + } p +=get_word (p, &word);Signature · 1 line
2.24.0.windows.2.