[v2] eal: fix memory leak when removing event_cb

Message ID 1593518201-27524-1-git-send-email-wangyunjian@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series [v2] eal: fix memory leak when removing event_cb |

Checks

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

Commit Message

Yunjian Wang June 30, 2020, 11:56 a.m. UTC
From: Yunjian Wang <wangyunjian@huawei.com>

The event_cb->dev_name is not freed when freeing event_cb,
and this causes a memory leak.

Fixes: a753e53d517b ("eal: add device event monitor framework")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 lib/librte_eal/common/eal_common_dev.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Guo, Jia July 2, 2020, 9:28 a.m. UTC | #1
hi, yunjian

On 6/30/2020 7:56 PM, wangyunjian wrote:

> From: Yunjian Wang <wangyunjian@huawei.com>
>
> The event_cb->dev_name is not freed when freeing event_cb,
> and this causes a memory leak.
>
> Fixes: a753e53d517b ("eal: add device event monitor framework")
> Cc: stable@dpdk.org
>
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>   lib/librte_eal/common/eal_common_dev.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
> index 9e4f09d..4cfdb80 100644
> --- a/lib/librte_eal/common/eal_common_dev.c
> +++ b/lib/librte_eal/common/eal_common_dev.c
> @@ -526,6 +526,8 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
>   		 */
>   		if (event_cb->active == 0) {
>   			TAILQ_REMOVE(&dev_event_cbs, event_cb, next);
> +			if (event_cb->dev_name)
> +				free(event_cb->dev_name);
>   			free(event_cb);
>   			ret++;
>   		} else {


Could you please to check is there another part need to check memory 
leak like that, such as in rte_dev_event_callback_register?
  
Yunjian Wang July 2, 2020, 10:53 a.m. UTC | #2
Hi, Jeff

> -----Original Message-----
> From: Jeff Guo [mailto:jia.guo@intel.com]
> Sent: Thursday, July 2, 2020 5:28 PM
> To: wangyunjian <wangyunjian@huawei.com>; dev@dpdk.org
> Cc: Lilijun (Jerry) <jerry.lilijun@huawei.com>; xudingke
> <xudingke@huawei.com>; stable@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v2] eal: fix memory leak when removing
> event_cb
> 
> hi, yunjian
> 
> On 6/30/2020 7:56 PM, wangyunjian wrote:
> 
> > From: Yunjian Wang <wangyunjian@huawei.com>
> >
> > The event_cb->dev_name is not freed when freeing event_cb,
> > and this causes a memory leak.
> >
> > Fixes: a753e53d517b ("eal: add device event monitor framework")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > ---
> >   lib/librte_eal/common/eal_common_dev.c | 2 ++
> >   1 file changed, 2 insertions(+)
> >
> > diff --git a/lib/librte_eal/common/eal_common_dev.c
> b/lib/librte_eal/common/eal_common_dev.c
> > index 9e4f09d..4cfdb80 100644
> > --- a/lib/librte_eal/common/eal_common_dev.c
> > +++ b/lib/librte_eal/common/eal_common_dev.c
> > @@ -526,6 +526,8 @@ static int cmp_dev_name(const struct rte_device
> *dev, const void *_name)
> >   		 */
> >   		if (event_cb->active == 0) {
> >   			TAILQ_REMOVE(&dev_event_cbs, event_cb, next);
> > +			if (event_cb->dev_name)
> > +				free(event_cb->dev_name);
> >   			free(event_cb);
> >   			ret++;
> >   		} else {
> 
> 
> Could you please to check is there another part need to check memory
> leak like that, such as in rte_dev_event_callback_register?

Yes, I have checked and find some same problems. I will also fix them.

Thanks,
Yunjian
  

Patch

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 9e4f09d..4cfdb80 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -526,6 +526,8 @@  static int cmp_dev_name(const struct rte_device *dev, const void *_name)
 		 */
 		if (event_cb->active == 0) {
 			TAILQ_REMOVE(&dev_event_cbs, event_cb, next);
+			if (event_cb->dev_name)
+				free(event_cb->dev_name);
 			free(event_cb);
 			ret++;
 		} else {