Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix Windows thread handle leak
  • Loading branch information
def- committed Sep 5, 2015
1 parent a1e9f07 commit 7487923
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 61 deletions.
5 changes: 2 additions & 3 deletions src/base/system.c
Expand Up @@ -49,6 +49,7 @@

#elif defined(CONF_FAMILY_WINDOWS)
#define WIN32_LEAN_AND_MEAN
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0501 /* required for mingw to get getaddrinfo to work */
#include <windows.h>
#include <winsock2.h>
Expand Down Expand Up @@ -181,9 +182,7 @@ void dbg_enable_threaded()
dbg_msg_threaded = 1;

Thread = thread_init(dbg_msg_thread, 0);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)Thread);
#endif
thread_detach(Thread);
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/engine/shared/fifoconsole.cpp
Expand Up @@ -28,7 +28,7 @@ FifoConsole::FifoConsole(IConsole *pConsole, char *pFifoFile, int flag)
m_pConsole = pConsole;
m_flag = flag;

pthread_detach((pthread_t)m_pFifoThread);
thread_detach(m_pFifoThread);
}

FifoConsole::~FifoConsole()
Expand Down
4 changes: 1 addition & 3 deletions src/game/editor/editor.cpp
Expand Up @@ -5466,9 +5466,7 @@ void CEditor::DoMapBorder()
void CEditor::CreateUndoStep()
{
void *CreateThread = thread_init(CreateUndoStepThread, this);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)CreateThread);
#endif
thread_detach(CreateThread);
}

void CEditor::CreateUndoStepThread(void *pUser)
Expand Down
4 changes: 1 addition & 3 deletions src/game/server/score/file_score.cpp
Expand Up @@ -96,9 +96,7 @@ void CFileScore::SaveScoreThread(void *pUser)
void CFileScore::Save()
{
void *pSaveThread = thread_init(SaveScoreThread, this);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)pSaveThread);
#endif
thread_detach(pSaveThread);
}

void CFileScore::Init()
Expand Down
68 changes: 17 additions & 51 deletions src/game/server/score/sql_score.cpp
Expand Up @@ -279,9 +279,7 @@ void CSqlScore::LoadScore(int ClientID)
Tmp->m_pSqlData = this;

void *LoadThread = thread_init(LoadScoreThread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)LoadThread);
#endif
thread_detach(LoadThread);
}

void CSqlScore::SaveTeamScoreThread(void *pUser)
Expand Down Expand Up @@ -416,9 +414,7 @@ void CSqlScore::MapVote(int ClientID, const char* MapName)
Tmp->m_pSqlData = this;

void *VoteThread = thread_init(MapVoteThread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)VoteThread);
#endif
thread_detach(VoteThread);
}

void CSqlScore::MapVoteThread(void *pUser)
Expand Down Expand Up @@ -518,9 +514,7 @@ void CSqlScore::MapInfo(int ClientID, const char* MapName)
Tmp->m_pSqlData = this;

void *InfoThread = thread_init(MapInfoThread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)InfoThread);
#endif
thread_detach(InfoThread);
}

void CSqlScore::MapInfoThread(void *pUser)
Expand Down Expand Up @@ -693,9 +687,7 @@ void CSqlScore::SaveScore(int ClientID, float Time, float CpTime[NUM_CHECKPOINTS
Tmp->m_pSqlData = this;

void *SaveThread = thread_init(SaveScoreThread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)SaveThread);
#endif
thread_detach(SaveThread);
}

void CSqlScore::SaveTeamScore(int* aClientIDs, unsigned int Size, float Time)
Expand All @@ -714,9 +706,7 @@ void CSqlScore::SaveTeamScore(int* aClientIDs, unsigned int Size, float Time)
Tmp->m_pSqlData = this;

void *SaveTeamThread = thread_init(SaveTeamScoreThread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)SaveTeamThread);
#endif
thread_detach(SaveTeamThread);
}

void CSqlScore::ShowTeamRankThread(void *pUser)
Expand Down Expand Up @@ -983,9 +973,7 @@ void CSqlScore::ShowTeamRank(int ClientID, const char* pName, bool Search)
Tmp->m_pSqlData = this;

void *TeamRankThread = thread_init(ShowTeamRankThread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)TeamRankThread);
#endif
thread_detach(TeamRankThread);
}

void CSqlScore::ShowRank(int ClientID, const char* pName, bool Search)
Expand All @@ -998,9 +986,7 @@ void CSqlScore::ShowRank(int ClientID, const char* pName, bool Search)
Tmp->m_pSqlData = this;

void *RankThread = thread_init(ShowRankThread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)RankThread);
#endif
thread_detach(RankThread);
}

void CSqlScore::ShowTop5Thread(void *pUser)
Expand Down Expand Up @@ -1152,9 +1138,7 @@ void CSqlScore::ShowTeamTop5(IConsole::IResult *pResult, int ClientID, void *pUs
Tmp->m_pSqlData = this;

void *TeamTop5Thread = thread_init(ShowTeamTop5Thread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)TeamTop5Thread);
#endif
thread_detach(TeamTop5Thread);
}

void CSqlScore::ShowTop5(IConsole::IResult *pResult, int ClientID, void *pUserData, int Debut)
Expand All @@ -1165,9 +1149,7 @@ void CSqlScore::ShowTop5(IConsole::IResult *pResult, int ClientID, void *pUserDa
Tmp->m_pSqlData = this;

void *Top5Thread = thread_init(ShowTop5Thread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)Top5Thread);
#endif
thread_detach(Top5Thread);
}

void CSqlScore::ShowTimes(int ClientID, int Debut)
Expand All @@ -1179,9 +1161,7 @@ void CSqlScore::ShowTimes(int ClientID, int Debut)
Tmp->m_Search = false;

void *TimesThread = thread_init(ShowTimesThread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)TimesThread);
#endif
thread_detach(TimesThread);
}

void CSqlScore::ShowTimes(int ClientID, const char* pName, int Debut)
Expand All @@ -1194,9 +1174,7 @@ void CSqlScore::ShowTimes(int ClientID, const char* pName, int Debut)
Tmp->m_Search = true;

void *TimesThread = thread_init(ShowTimesThread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)TimesThread);
#endif
thread_detach(TimesThread);
}

void CSqlScore::FuzzyString(char *pString)
Expand Down Expand Up @@ -1399,9 +1377,7 @@ void CSqlScore::ShowPoints(int ClientID, const char* pName, bool Search)
Tmp->m_pSqlData = this;

void *PointsThread = thread_init(ShowPointsThread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)PointsThread);
#endif
thread_detach(PointsThread);
}

void CSqlScore::ShowTopPointsThread(void *pUser)
Expand Down Expand Up @@ -1463,9 +1439,7 @@ void CSqlScore::ShowTopPoints(IConsole::IResult *pResult, int ClientID, void *pU
Tmp->m_pSqlData = this;

void *TopPointsThread = thread_init(ShowTopPointsThread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)TopPointsThread);
#endif
thread_detach(TopPointsThread);
}

void CSqlScore::RandomMapThread(void *pUser)
Expand Down Expand Up @@ -1589,9 +1563,7 @@ void CSqlScore::RandomMap(int ClientID, int stars)
Tmp->m_pSqlData = this;

void *RandomThread = thread_init(RandomMapThread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)RandomThread);
#endif
thread_detach(RandomThread);
}

void CSqlScore::RandomUnfinishedMap(int ClientID, int stars)
Expand All @@ -1603,9 +1575,7 @@ void CSqlScore::RandomUnfinishedMap(int ClientID, int stars)
Tmp->m_pSqlData = this;

void *RandomUnfinishedThread = thread_init(RandomUnfinishedMapThread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)RandomUnfinishedThread);
#endif
thread_detach(RandomUnfinishedThread);
}

void CSqlScore::SaveTeam(int Team, const char* Code, int ClientID, const char* Server)
Expand All @@ -1630,9 +1600,7 @@ void CSqlScore::SaveTeam(int Team, const char* Code, int ClientID, const char* S
Tmp->m_pSqlData = this;

void *SaveThread = thread_init(SaveTeamThread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)SaveThread);
#endif
thread_detach(SaveThread);
}

void CSqlScore::SaveTeamThread(void *pUser)
Expand Down Expand Up @@ -1745,9 +1713,7 @@ void CSqlScore::LoadTeam(const char* Code, int ClientID)
Tmp->m_pSqlData = this;

void *LoadThread = thread_init(LoadTeamThread, Tmp);
#if defined(CONF_FAMILY_UNIX)
pthread_detach((pthread_t)LoadThread);
#endif
thread_detach(LoadThread);
}

void CSqlScore::LoadTeamThread(void *pUser)
Expand Down

0 comments on commit 7487923

Please sign in to comment.