Skip to content

Commit

Permalink
set ping threads to NULL after joining to prevent potential dangling …
Browse files Browse the repository at this point in the history
…pointers
  • Loading branch information
timbergeron committed Oct 23, 2024
1 parent 9fa6530 commit efb2e58
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Quake/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -5916,9 +5916,15 @@ void WaitForPingThreads(SDL_Thread* thread1, SDL_Thread* thread2)
pingThreadsShouldExit = true; // Signal threads to exit

if (thread1)
{
SDL_WaitThread(thread1, NULL);
thread1 = NULL; // Set to NULL after joining
}
if (thread2)
{
SDL_WaitThread(thread2, NULL);
thread2 = NULL; // Set to NULL after joining
}

pingThreadsShouldExit = false; // Reset the exit flag

Expand Down Expand Up @@ -6307,11 +6313,14 @@ void CleanupPingThreads()
{
WaitForPingThreads(serversmenu.pingThreads[0], serversmenu.pingThreads[1]);

if (!serversmenu.pingThreadRunning)
if (serversmenu.pingThreadRunning)
{
pingThreadsShouldExit = true;
if (serversmenu.pingThread)
{
SDL_WaitThread(serversmenu.pingThread, NULL);
serversmenu.pingThread = NULL; // Set to NULL after joining
}
}

CleanupPingMutex();
Expand Down

0 comments on commit efb2e58

Please sign in to comment.