From 7487923774df3a372bb3618087a0753b435acf8d Mon Sep 17 00:00:00 2001 From: def Date: Sat, 5 Sep 2015 04:49:22 +0200 Subject: [PATCH] Fix Windows thread handle leak --- src/base/system.c | 5 +- src/engine/shared/fifoconsole.cpp | 2 +- src/game/editor/editor.cpp | 4 +- src/game/server/score/file_score.cpp | 4 +- src/game/server/score/sql_score.cpp | 68 +++++++--------------------- 5 files changed, 22 insertions(+), 61 deletions(-) diff --git a/src/base/system.c b/src/base/system.c index 7c373ac26..f363f88a2 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -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 #include @@ -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 diff --git a/src/engine/shared/fifoconsole.cpp b/src/engine/shared/fifoconsole.cpp index 1ec34ee2e..7d3b5c748 100644 --- a/src/engine/shared/fifoconsole.cpp +++ b/src/engine/shared/fifoconsole.cpp @@ -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() diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index f56afa505..6b37e5e88 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -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) diff --git a/src/game/server/score/file_score.cpp b/src/game/server/score/file_score.cpp index 45e687f8f..34df4e13c 100644 --- a/src/game/server/score/file_score.cpp +++ b/src/game/server/score/file_score.cpp @@ -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() diff --git a/src/game/server/score/sql_score.cpp b/src/game/server/score/sql_score.cpp index 97b00bf69..55e1ca937 100644 --- a/src/game/server/score/sql_score.cpp +++ b/src/game/server/score/sql_score.cpp @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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)