[dpdk-dev] eal: fix memory leak

Message ID 1525256792-24191-1-git-send-email-jianfeng.tan@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers

Checks

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

Commit Message

Jianfeng Tan May 2, 2018, 10:26 a.m. UTC
  params is not freed if pthread_create() fails. The fix is
straight-forward.

Fixes: 3d09a6e26d8b ("eal: fix threads block on barrier")

Reported-by: Olivier Matz <olivier.matz@6wind.com>
Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 lib/librte_eal/common/eal_common_thread.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Olivier Matz May 2, 2018, 11:09 a.m. UTC | #1
On Wed, May 02, 2018 at 10:26:32AM +0000, Jianfeng Tan wrote:
> params is not freed if pthread_create() fails. The fix is
> straight-forward.
> 
> Fixes: 3d09a6e26d8b ("eal: fix threads block on barrier")
> 
> Reported-by: Olivier Matz <olivier.matz@6wind.com>
> Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>

Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
  
Thomas Monjalon May 2, 2018, 3:17 p.m. UTC | #2
02/05/2018 13:09, Olivier Matz:
> On Wed, May 02, 2018 at 10:26:32AM +0000, Jianfeng Tan wrote:
> > params is not freed if pthread_create() fails. The fix is
> > straight-forward.
> > 
> > Fixes: 3d09a6e26d8b ("eal: fix threads block on barrier")
> > 
> > Reported-by: Olivier Matz <olivier.matz@6wind.com>
> > Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
> 
> Reviewed-by: Olivier Matz <olivier.matz@6wind.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_eal/common/eal_common_thread.c b/lib/librte_eal/common/eal_common_thread.c
index 5f0c61f..c18a112 100644
--- a/lib/librte_eal/common/eal_common_thread.c
+++ b/lib/librte_eal/common/eal_common_thread.c
@@ -183,8 +183,10 @@  rte_ctrl_thread_create(pthread_t *thread, const char *name,
 	pthread_barrier_init(&params->configured, NULL, 2);
 
 	ret = pthread_create(thread, attr, rte_thread_init, (void *)params);
-	if (ret != 0)
+	if (ret != 0) {
+		free(params);
 		return ret;
+	}
 
 	if (name != NULL) {
 		ret = rte_thread_setname(*thread, name);