SDL: testatomic: destroy threads + free all memory at quit to fix --trackmem (799ed)

From 799ede831e047b3c295eb3df6b72ae486e332c60 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Mon, 13 May 2024 16:05:55 +0200
Subject: [PATCH] testatomic: destroy threads + free all memory at quit to fix
 --trackmem

(cherry picked from commit 831c79d32f44b536a6f8973e67be4a204783b36a)
---
 test/testatomic.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/test/testatomic.c b/test/testatomic.c
index 75325e00e0f62..e8d43d1ef7bc1 100644
--- a/test/testatomic.c
+++ b/test/testatomic.c
@@ -132,6 +132,7 @@ static void runAdder(void)
 {
     Uint32 start, end;
     int T = NThreads;
+    SDL_Thread *threads[NThreads];
 
     start = SDL_GetTicks();
 
@@ -139,14 +140,18 @@ static void runAdder(void)
 
     SDL_AtomicSet(&threadsRunning, NThreads);
 
-    while (T--) {
-        SDL_CreateThread(adder, "Adder", NULL);
+    for (i = 0; i < NThreads; i++) {
+        threads[i] = SDL_CreateThread(adder, "Adder", NULL);
     }
 
     while (SDL_AtomicGet(&threadsRunning) > 0) {
         SDL_SemWait(threadDone);
     }
 
+    for (i = 0; i < NThreads; i++) {
+        SDL_WaitThread(threads[i], NULL);
+    }
+
     SDL_DestroySemaphore(threadDone);
 
     end = SDL_GetTicks();
@@ -733,6 +738,7 @@ int main(int argc, char *argv[])
     RunFIFOTest(SDL_FALSE);
 #endif
     RunFIFOTest(SDL_TRUE);
+    SDL_Quit();
     SDLTest_CommonQuit(state);
     return 0;
 }