efd: fix tailq entry leak in error path

Message ID 49d4bdc58b81564788cfd31f16ef2e66c1673f6d.1601347917.git.wangyunjian@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series efd: fix tailq entry leak in error path |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-intel-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Yunjian Wang Sept. 29, 2020, 3:31 a.m. UTC
  From: Yunjian Wang <wangyunjian@huawei.com>

In rte_efd_create() allocated memory for tailq entry, we should
free it when error happens, otherwise it will lead to memory leak.

Fixes: 56b6ef874f80 ("efd: new Elastic Flow Distributor library")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 lib/librte_efd/rte_efd.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Thomas Monjalon Oct. 20, 2020, 2:10 p.m. UTC | #1
Byron, Yipeng,
Please could you review?
Thanks

29/09/2020 05:31, wangyunjian:
> From: Yunjian Wang <wangyunjian@huawei.com>
> 
> In rte_efd_create() allocated memory for tailq entry, we should
> free it when error happens, otherwise it will lead to memory leak.
> 
> Fixes: 56b6ef874f80 ("efd: new Elastic Flow Distributor library")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>  lib/librte_efd/rte_efd.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/lib/librte_efd/rte_efd.c b/lib/librte_efd/rte_efd.c
> index 6a799556d..0aa120f48 100644
> --- a/lib/librte_efd/rte_efd.c
> +++ b/lib/librte_efd/rte_efd.c
> @@ -707,6 +707,7 @@ rte_efd_create(const char *name, uint32_t max_num_rules, uint32_t key_len,
>  
>  error_unlock_exit:
>  	rte_mcfg_tailq_write_unlock();
> +	rte_free(te);
>  	rte_efd_free(table);
>  
>  	return NULL;
>
  
Wang, Yipeng1 Oct. 20, 2020, 8:24 p.m. UTC | #2
> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Tuesday, October 20, 2020 7:11 AM
> To: Marohn, Byron <byron.marohn@intel.com>; Wang, Yipeng1
> <yipeng1.wang@intel.com>
> Cc: dev@dpdk.org; jerry.lilijun@huawei.com; xudingke@huawei.com; Yunjian
> Wang <wangyunjian@huawei.com>; stable@dpdk.org; wangyunjian
> <wangyunjian@huawei.com>
> Subject: Re: [dpdk-dev] [PATCH] efd: fix tailq entry leak in error path
> 
> Byron, Yipeng,
> Please could you review?
> Thanks
> 
> 29/09/2020 05:31, wangyunjian:
> > From: Yunjian Wang <wangyunjian@huawei.com>
> >
> > In rte_efd_create() allocated memory for tailq entry, we should free
> > it when error happens, otherwise it will lead to memory leak.
> >
> > Fixes: 56b6ef874f80 ("efd: new Elastic Flow Distributor library")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > ---
> >  lib/librte_efd/rte_efd.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/lib/librte_efd/rte_efd.c b/lib/librte_efd/rte_efd.c index
> > 6a799556d..0aa120f48 100644
> > --- a/lib/librte_efd/rte_efd.c
> > +++ b/lib/librte_efd/rte_efd.c
> > @@ -707,6 +707,7 @@ rte_efd_create(const char *name, uint32_t
> > max_num_rules, uint32_t key_len,
> >
> >  error_unlock_exit:
> >  	rte_mcfg_tailq_write_unlock();
> > +	rte_free(te);
> >  	rte_efd_free(table);
> >
> >  	return NULL;
> >
[Wang, Yipeng] 
Thanks for the patch and sorry for the delay. The code looks good.
Acked-by: Yipeng Wang <yipeng1.wang@intel.com>
  
David Marchand Oct. 22, 2020, 8:06 p.m. UTC | #3
On Tue, Sep 29, 2020 at 5:32 AM wangyunjian <wangyunjian@huawei.com> wrote:
>
> From: Yunjian Wang <wangyunjian@huawei.com>
>
> In rte_efd_create() allocated memory for tailq entry, we should
> free it when error happens, otherwise it will lead to memory leak.
>
> Fixes: 56b6ef874f80 ("efd: new Elastic Flow Distributor library")
> Cc: stable@dpdk.org
>
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Acked-by: Yipeng Wang <yipeng1.wang@intel.com>

Applied, thanks.
  

Patch

diff --git a/lib/librte_efd/rte_efd.c b/lib/librte_efd/rte_efd.c
index 6a799556d..0aa120f48 100644
--- a/lib/librte_efd/rte_efd.c
+++ b/lib/librte_efd/rte_efd.c
@@ -707,6 +707,7 @@  rte_efd_create(const char *name, uint32_t max_num_rules, uint32_t key_len,
 
 error_unlock_exit:
 	rte_mcfg_tailq_write_unlock();
+	rte_free(te);
 	rte_efd_free(table);
 
 	return NULL;