Skip to content

Commit

Permalink
fix(thread): memory leak bug when running test
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Feb 9, 2018
1 parent 18f454b commit 402bc03
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/thread/pthread/thread.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* ***************************************************************************
* thread.c -- the pthread edition thread opreation set.
*
* Copyright (C) 2013-2017 by Liu Chao <[email protected]>
* Copyright (C) 2013-2018 by Liu Chao <[email protected]>
*
* This file is part of the LCUI project, and may only be used, modified, and
* distributed under the terms of the GPLv2.
Expand All @@ -22,7 +22,7 @@
/* ****************************************************************************
* thread.c -- pthread版的线程操作集
*
* 版权所有 (C) 2013-2017 归属于 刘超 <[email protected]>
* 版权所有 (C) 2013-2018 归属于 刘超 <[email protected]>
*
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
*
Expand Down Expand Up @@ -62,7 +62,11 @@ static void *LCUIThread_Run( void *arg )
{
LCUI_ThreadContext ctx = arg;
ctx->func( ctx->arg );
return NULL;
LCUIMutex_Lock( &self.mutex );
LinkedList_Unlink( &self.threads, &ctx->node );
LCUIMutex_Unlock( &self.mutex );
free( ctx );
pthread_exit( NULL );
}

static LCUI_ThreadContext LCUIThread_Find( LCUI_Thread tid )
Expand Down Expand Up @@ -129,10 +133,9 @@ void LCUIThread_Exit( void *retval )
LCUI_ThreadContext ctx;
tid = LCUIThread_SelfID();
ctx = LCUIThread_Get( tid );
if( !ctx ) {
return;
if( ctx ) {
free( ctx );
}
free( ctx );
pthread_exit( retval );
}

Expand Down

0 comments on commit 402bc03

Please sign in to comment.