From 728bf363cbc45fe197393d94c68b87b770d672b2 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 28 Jul 2024 07:46:44 -0700 Subject: [PATCH] Make sure we call SDL_Quit() before SDLTest_CommonDestroyState() Otherwise we'll report leaks that will be cleaned up in SDL_Quit() --- include/SDL3/SDL_test_common.h | 2 ++ test/loopwave.c | 1 + test/testaudiorecording.c | 2 +- test/testcamera.c | 1 + test/testevdev.c | 1 + test/testfile.c | 1 + test/testplatform.c | 2 +- test/testqsort.c | 1 + test/testrwlock.c | 2 +- test/testsensor.c | 2 ++ test/teststreaming.c | 1 + test/testthread.c | 2 +- test/testyuv.c | 1 + test/torturethread.c | 1 + 14 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/SDL3/SDL_test_common.h b/include/SDL3/SDL_test_common.h index a7ec4dfca..76ea5e45c 100644 --- a/include/SDL3/SDL_test_common.h +++ b/include/SDL3/SDL_test_common.h @@ -156,6 +156,8 @@ SDLTest_CommonState *SDLTest_CommonCreateState(char **argv, SDL_InitFlags flags) /** * Free the common state object. * + * You should call SDL_Quit() before calling this function. + * * \param state The common state object to destroy */ void SDLTest_CommonDestroyState(SDLTest_CommonState *state); diff --git a/test/loopwave.c b/test/loopwave.c index 45bc060c8..06bb16800 100644 --- a/test/loopwave.c +++ b/test/loopwave.c @@ -134,6 +134,7 @@ void SDL_AppQuit(void *appstate) { SDL_DestroyAudioStream(stream); SDL_free(wave.sound); + SDL_Quit(); SDLTest_CommonDestroyState(state); } diff --git a/test/testaudiorecording.c b/test/testaudiorecording.c index b983143c4..cd0dbb63a 100644 --- a/test/testaudiorecording.c +++ b/test/testaudiorecording.c @@ -210,8 +210,8 @@ void SDL_AppQuit(void *appstate) SDL_DestroyAudioStream(stream_out); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); - SDLTest_CommonDestroyState(state); SDL_Quit(); + SDLTest_CommonDestroyState(state); } diff --git a/test/testcamera.c b/test/testcamera.c index a600e447d..09d9a4841 100644 --- a/test/testcamera.c +++ b/test/testcamera.c @@ -74,6 +74,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[]) NULL, }; SDLTest_CommonLogUsage(state, argv[0], options); + SDL_Quit(); SDLTest_CommonDestroyState(state); return 1; } diff --git a/test/testevdev.c b/test/testevdev.c index daa0a6a94..e2442e39f 100644 --- a/test/testevdev.c +++ b/test/testevdev.c @@ -2243,6 +2243,7 @@ int main(int argc, char *argv[]) result = run_test() ? 0 : 1; + SDL_Quit(); SDLTest_CommonDestroyState(state); return result; } diff --git a/test/testfile.c b/test/testfile.c index a2eab48f8..f975f0cf7 100644 --- a/test/testfile.c +++ b/test/testfile.c @@ -58,6 +58,7 @@ iostrm_error_quit(unsigned line, SDL_IOStream *iostrm) SDL_CloseIO(iostrm); } cleanup(); + SDL_Quit(); SDLTest_CommonDestroyState(state); exit(1); /* quit with iostrm error (test failed) */ } diff --git a/test/testplatform.c b/test/testplatform.c index aac7165b1..55cb0134a 100644 --- a/test/testplatform.c +++ b/test/testplatform.c @@ -483,8 +483,8 @@ int main(int argc, char *argv[]) status += Test64Bit(verbose); status += TestCPUInfo(verbose); status += TestAssertions(verbose); - SDL_Quit(); + SDL_Quit(); SDLTest_CommonDestroyState(state); return status; diff --git a/test/testqsort.c b/test/testqsort.c index 8ea18c03f..caa4a05f2 100644 --- a/test/testqsort.c +++ b/test/testqsort.c @@ -135,6 +135,7 @@ int main(int argc, char *argv[]) test_sort("random sorted", nums, arraylen); } + SDL_Quit(); SDLTest_CommonDestroyState(state); return 0; diff --git a/test/testrwlock.c b/test/testrwlock.c index 0569ada16..328aa6886 100644 --- a/test/testrwlock.c +++ b/test/testrwlock.c @@ -171,8 +171,8 @@ int main(int argc, char *argv[]) SDL_Log("Reader threads have terminated, quitting!"); SDL_DestroyRWLock(rwlock); - SDLTest_CommonDestroyState(state); SDL_Quit(); + SDLTest_CommonDestroyState(state); return 0; } diff --git a/test/testsensor.c b/test/testsensor.c index 404c9723b..1e35fba65 100644 --- a/test/testsensor.c +++ b/test/testsensor.c @@ -72,6 +72,7 @@ int main(int argc, char **argv) SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); if (!SDLTest_CommonDefaultArgs(state, argc, argv)) { + SDL_Quit(); SDLTest_CommonDestroyState(state); return 1; } @@ -79,6 +80,7 @@ int main(int argc, char **argv) /* Load the SDL library */ if (SDL_Init(SDL_INIT_SENSOR) < 0) { SDL_Log("Couldn't initialize SDL: %s\n", SDL_GetError()); + SDL_Quit(); SDLTest_CommonDestroyState(state); return 1; } diff --git a/test/teststreaming.c b/test/teststreaming.c index 3a511d8a0..148ca04cd 100644 --- a/test/teststreaming.c +++ b/test/teststreaming.c @@ -149,6 +149,7 @@ int main(int argc, char **argv) SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); if (!SDLTest_CommonDefaultArgs(state, argc, argv)) { + SDL_Quit(); SDLTest_CommonDestroyState(state); return 1; } diff --git a/test/testthread.c b/test/testthread.c index dd282e9d4..2c50200ca 100644 --- a/test/testthread.c +++ b/test/testthread.c @@ -28,8 +28,8 @@ static SDLTest_CommonState *state; static void quit(int rc) { - SDLTest_CommonDestroyState(state); SDL_Quit(); + SDLTest_CommonDestroyState(state); /* Let 'main()' return normally */ if (rc != 0) { exit(rc); diff --git a/test/testyuv.c b/test/testyuv.c index cf207119d..822d3f157 100644 --- a/test/testyuv.c +++ b/test/testyuv.c @@ -396,6 +396,7 @@ int main(int argc, char **argv) NULL, }; SDLTest_CommonLogUsage(state, argv[0], options); + SDL_Quit(); SDLTest_CommonDestroyState(state); return 1; } diff --git a/test/torturethread.c b/test/torturethread.c index 83bb76c21..c45f89c9c 100644 --- a/test/torturethread.c +++ b/test/torturethread.c @@ -98,6 +98,7 @@ int main(int argc, char *argv[]) } if (!SDLTest_CommonDefaultArgs(state, argc, argv)) { + SDL_Quit(); SDLTest_CommonDestroyState(state); return 1; }