From: Benjamin Marzinski Subject: Re: [PATCH] libmultipath: free pgp if add_pathgroup fails in disassemble_map func Date: Wed, 22 Jul 2020 15:48:44 -0500 Message-ID: <20200722204843.GJ11089@octiron.msp.redhat.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com Content-Disposition: inline To: Zhiqiang Liu Cc: lixiaokeng , Yanxiaodan , linfeilong , dm-devel@redhat.com, Zdenek Kabelac , Martin Wilck List-Id: dm-devel.ids On Wed, Jul 22, 2020 at 04:36:04PM +0800, Zhiqiang Liu wrote: > 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. > Reviewed-by: Benjamin Marzinski > Signed-off-by: Zhiqiang Liu > Signed-off-by: lixiaokeng > --- > libmultipath/dmparser.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/libmultipath/dmparser.c b/libmultipath/dmparser.c > index ac13ec06..6225838b 100644 > --- a/libmultipath/dmparser.c > +++ b/libmultipath/dmparser.c > @@ -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); > > -- > 2.24.0.windows.2 >