1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2026-03-09 17:59:19 +03:00

Compare commits

...

6 Commits

Author SHA1 Message Date
9d27b935b7 Merge pull request #2223 from synqa/fix-memory-leak-loadlanglist
Fix memory leak in LoadLangList()
2026-02-06 15:56:18 +01:00
1e1104d3ba Merge pull request #2221 from synqa/fix-halt-flag
Fix data race on Tick64
2026-02-06 15:55:01 +01:00
074efb5479 Merge pull request #2220 from synqa/fix-thread-counter
Fix race condition in thread counter
2026-02-06 15:54:18 +01:00
fe460de5a6 Fix data race on Tick64
Add lock protection when reading/writing Halt flag to prevent data race.
2026-02-06 21:12:16 +09:00
6ef941db21 Fix memory leak in LoadLangList() 2026-02-06 21:08:52 +09:00
d7d3ec8cac Fix race condition in thread counter
To prevent data races caused by concurrent access from multiple threads,
replace UINT with COUNTER.
2026-02-06 21:03:08 +09:00
3 changed files with 23 additions and 7 deletions

View File

@ -63,7 +63,7 @@ static int ydays[] =
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
};
static UINT current_num_thread = 0;
static COUNTER *current_num_thread = NULL;
static UINT cached_number_of_cpus = 0;
@ -776,6 +776,7 @@ void InitThreading()
{
thread_pool = NewSk();
thread_count = NewCounter();
current_num_thread = NewCounter();
}
// Release of thread pool
@ -821,6 +822,9 @@ void FreeThreading()
DeleteCounter(thread_count);
thread_count = NULL;
DeleteCounter(current_num_thread);
current_num_thread = NULL;
}
// Thread pool procedure
@ -1028,9 +1032,9 @@ THREAD *NewThreadNamed(THREAD_PROC *thread_proc, void *param, char *name)
Wait(pd->InitFinishEvent, INFINITE);
current_num_thread++;
Inc(current_num_thread);
// Debug("current_num_thread = %u\n", current_num_thread);
// Debug("current_num_thread = %u\n", Count(current_num_thread));
return ret;
}
@ -1055,8 +1059,8 @@ void CleanupThread(THREAD *t)
Free(t);
current_num_thread--;
//Debug("current_num_thread = %u\n", current_num_thread);
Dec(current_num_thread);
//Debug("current_num_thread = %u\n", Count(current_num_thread));
}
// Release thread (pool)

View File

@ -470,6 +470,7 @@ LIST *LoadLangList()
b = ReadDump(filename);
if (b == NULL)
{
FreeLangList(o);
return NULL;
}

View File

@ -139,6 +139,7 @@ void Tick64Thread(THREAD *thread, void *param)
{
UINT tick;
UINT64 tick64;
bool halt;
#ifndef OS_WIN32
tick = TickRealtime(); // Get the current system clock
@ -228,7 +229,13 @@ void Tick64Thread(THREAD *thread, void *param)
n = 0;
}
if (tk64->Halt)
Lock(tk64->TickLock);
{
halt = tk64->Halt;
}
Unlock(tk64->TickLock);
if (halt)
{
break;
}
@ -286,7 +293,11 @@ void FreeTick64()
}
// Termination process
tk64->Halt = true;
Lock(tk64->TickLock);
{
tk64->Halt = true;
}
Unlock(tk64->TickLock);
Set(halt_tick_event);
WaitThread(tk64->Thread, INFINITE);
ReleaseThread(tk64->Thread);