[dpdk-dev] member: fix memory leak on error

Message ID 5c0a540f8917604a86e18f8da77fa0c2013b7fde.1513865858.git.anatoly.burakov@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Anatoly Burakov Dec. 21, 2017, 5:50 p.m. UTC
  rte_member may have allocated a tailq entry before failure, so
free it.

Fixes: 857ed6c68cf2 ("member: implement main API")
Cc: yipeng1.wang@intel.com
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_member/rte_member.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Wang, Yipeng1 Dec. 22, 2017, 12:01 a.m. UTC | #1
Thank you Anatoly for finding this issue. In the code I tried to reuse the rte_member_free function to free memory but it may not be executed through. 

Because of this, I may not properly release setsum struct neither. I will post a fix for both soon.

Thanks

>-----Original Message-----
>From: Burakov, Anatoly
>Sent: Thursday, December 21, 2017 9:51 AM
>To: dev@dpdk.org
>Cc: Wang, Yipeng1 <yipeng1.wang@intel.com>; Gobriel, Sameh
><sameh.gobriel@intel.com>
>Subject: [PATCH] member: fix memory leak on error
>
>rte_member may have allocated a tailq entry before failure, so
>free it.
>
>Fixes: 857ed6c68cf2 ("member: implement main API")
>Cc: yipeng1.wang@intel.com
>Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
>---
> lib/librte_member/rte_member.c | 1 +
> 1 file changed, 1 insertion(+)
>
>diff --git a/lib/librte_member/rte_member.c
>b/lib/librte_member/rte_member.c
>index cc9ea84..569fff9 100644
>--- a/lib/librte_member/rte_member.c
>+++ b/lib/librte_member/rte_member.c
>@@ -191,6 +191,7 @@ rte_member_create(const struct
>rte_member_parameters *params)
> 	return setsum;
>
> error_unlock_exit:
>+	rte_free(te);
> 	rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
> 	rte_member_free(setsum);
> 	return NULL;
>--
>2.7.4
  
Wang, Yipeng1 Dec. 22, 2017, 12:07 a.m. UTC | #2
Btw, Pablo, since I remember I refer to the EFD library on my membership implementation, does EFD have similar memory leakage issue that not releasing te when failure?

Thanks

>-----Original Message-----
>From: Wang, Yipeng1
>Sent: Thursday, December 21, 2017 4:01 PM
>To: Burakov, Anatoly <anatoly.burakov@intel.com>; dev@dpdk.org
>Cc: Gobriel, Sameh <sameh.gobriel@intel.com>
>Subject: RE: [PATCH] member: fix memory leak on error
>
>Thank you Anatoly for finding this issue. In the code I tried to reuse the
>rte_member_free function to free memory but it may not be executed
>through.
>
>Because of this, I may not properly release setsum struct neither. I will post a
>fix for both soon.
>
>Thanks
>
>>-----Original Message-----
>>From: Burakov, Anatoly
>>Sent: Thursday, December 21, 2017 9:51 AM
>>To: dev@dpdk.org
>>Cc: Wang, Yipeng1 <yipeng1.wang@intel.com>; Gobriel, Sameh
>><sameh.gobriel@intel.com>
>>Subject: [PATCH] member: fix memory leak on error
>>
>>rte_member may have allocated a tailq entry before failure, so
>>free it.
>>
>>Fixes: 857ed6c68cf2 ("member: implement main API")
>>Cc: yipeng1.wang@intel.com
>>Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
>>---
>> lib/librte_member/rte_member.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>>diff --git a/lib/librte_member/rte_member.c
>>b/lib/librte_member/rte_member.c
>>index cc9ea84..569fff9 100644
>>--- a/lib/librte_member/rte_member.c
>>+++ b/lib/librte_member/rte_member.c
>>@@ -191,6 +191,7 @@ rte_member_create(const struct
>>rte_member_parameters *params)
>> 	return setsum;
>>
>> error_unlock_exit:
>>+	rte_free(te);
>> 	rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
>> 	rte_member_free(setsum);
>> 	return NULL;
>>--
>>2.7.4
  
Anatoly Burakov Dec. 22, 2017, 9:20 a.m. UTC | #3
On 22-Dec-17 12:01 AM, Wang, Yipeng1 wrote:
> Thank you Anatoly for finding this issue. In the code I tried to reuse the rte_member_free function to free memory but it may not be executed through.
> 
> Because of this, I may not properly release setsum struct neither. I will post a fix for both soon.
> 
> Thanks

Yep, i can see that now. Didn't think to look inside rte_member_free() 
:/ However, you're creating a race condition there - you're unlocking a 
tailq, and then locking (and unlocking) it again inside 
rte_member_free() - it probably needs _thread_unsafe() functions that 
you can call from behind the lock.
  

Patch

diff --git a/lib/librte_member/rte_member.c b/lib/librte_member/rte_member.c
index cc9ea84..569fff9 100644
--- a/lib/librte_member/rte_member.c
+++ b/lib/librte_member/rte_member.c
@@ -191,6 +191,7 @@  rte_member_create(const struct rte_member_parameters *params)
 	return setsum;
 
 error_unlock_exit:
+	rte_free(te);
 	rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
 	rte_member_free(setsum);
 	return NULL;