From: mwilck@suse.com Subject: [PATCH v2 82/84] libmultipath: free pp if store_path fails in disassemble_map Date: Wed, 12 Aug 2020 13:35:59 +0200 Message-ID: <20200812113601.26658-3-mwilck@suse.com> References: <20200812113601.26658-1-mwilck@suse.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20200812113601.26658-1-mwilck@suse.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@redhat.com, Zhiqiang Liu List-Id: dm-devel.ids From: Zhiqiang Liu 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 Signed-off-by: lixiaokeng Signed-off-by: Martin Wilck --- libmultipath/dmparser.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libmultipath/dmparser.c b/libmultipath/dmparser.c index 25e6a4a..c103161 100644 --- a/libmultipath/dmparser.c +++ b/libmultipath/dmparser.c @@ -306,11 +306,15 @@ int disassemble_map(const struct _vector *pathvec, goto out1; strlcpy(pp->dev_t, word, BLK_DEV_SIZE); - } - FREE(word); - if (store_path(pgp->paths, pp)) - goto out; + if (store_path(pgp->paths, pp)) { + free_path(pp); + goto out1; + } + } else if (store_path(pgp->paths, pp)) + goto out1; + + FREE(word); pgp->id ^= (long)pp; pp->pgindex = i + 1; -- 2.28.0