tests: plug leaks when running with --trackmem

(using SDL_VIDEO_DRIVER=x11/wayland on Linux)
main
Anonymous Maarten 2023-08-22 18:44:28 +02:00 committed by Anonymous Maarten
parent f42bbeca24
commit 2a01f9dcb5
11 changed files with 93 additions and 97 deletions

View File

@ -15,8 +15,6 @@
pump the event loop and catch keystrokes.
*/
#include <stdlib.h>
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#endif
@ -25,22 +23,10 @@
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_test.h>
static SDL_Window *window;
static SDL_Renderer *renderer;
static SDLTest_CommonState *state;
static SDLTest_TextWindow *textwin;
static int done;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
SDL_Quit();
/* Let 'main()' return normally */
if (rc != 0) {
exit(rc);
}
}
static void
print_string(char **text, size_t *maxlen, const char *fmt, ...)
{
@ -171,6 +157,7 @@ PrintText(const char *eventtype, const char *text)
static void loop(void)
{
SDL_Event event;
int i;
/* Check for events */
/*SDL_WaitEvent(&event); emscripten does not like waiting*/
@ -234,11 +221,13 @@ static void loop(void)
}
}
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDLTest_TextWindowDisplay(textwin, renderer);
SDL_RenderPresent(renderer);
for (i = 0; i < state->num_windows; i++) {
SDL_SetRenderDrawColor(state->renderers[i], 0, 0, 0, 255);
SDL_RenderClear(state->renderers[i]);
SDL_SetRenderDrawColor(state->renderers[i], 255, 255, 255, 255);
SDLTest_TextWindowDisplay(textwin, state->renderers[i]);
SDL_RenderPresent(state->renderers[i]);
}
/* Slow down framerate */
SDL_Delay(100);
@ -252,13 +241,14 @@ static void loop(void)
int main(int argc, char *argv[])
{
SDLTest_CommonState *state;
int w, h;
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
return 1;
}
state->window_title = "CheckKeys Test";
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@ -275,31 +265,22 @@ int main(int argc, char *argv[])
SDL_SetHint(SDL_HINT_IME_SUPPORT_EXTENDED_TEXT, "1");
/* Initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
/* Set 640x480 video mode */
window = SDL_CreateWindow("CheckKeys Test", 640, 480, 0);
if (window == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n",
SDL_GetError());
quit(2);
}
renderer = SDL_CreateRenderer(window, NULL, 0);
if (renderer == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n",
SDL_GetError());
quit(2);
}
textwin = SDLTest_TextWindowCreate(0, 0, 640, 480);
SDL_GetWindowSize(state->windows[0], &w, &h);
textwin = SDLTest_TextWindowCreate(0.f, 0.f, (float)w, (float)h);
#ifdef __IOS__
{
int i;
/* Creating the context creates the view, which we need to show keyboard */
SDL_GL_CreateContext(window);
for (i = 0; i < state->num_windows; i++) {
SDL_GL_CreateContext(state->windows[i]);
}
}
#endif
SDL_StartTextInput();
@ -319,7 +300,8 @@ int main(int argc, char *argv[])
}
#endif
SDL_Quit();
SDLTest_CommonDestroyState(state);
SDLTest_TextWindowDestroy(textwin);
SDLTest_CleanupTextDrawing();
SDLTest_CommonQuit(state);
return 0;
}

View File

@ -303,6 +303,9 @@ int main(int argc, char *argv[])
}
#endif
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_WaitThread(thread, NULL);
SDL_Quit();
SDLTest_CommonDestroyState(state);

View File

@ -440,6 +440,7 @@ int main(int argc, char *argv[])
}
#endif
SDLTest_CleanupTextDrawing();
SDL_DestroyAudioStream(stream);
SDL_free(audio_buf);
SDLTest_CommonQuit(state);

View File

@ -2008,15 +2008,22 @@ int main(int argc, char *argv[])
HandleGamepadRemoved(controllers[0].id);
DelController(controllers[0].id);
}
SDL_free(controllers);
SDL_free(controller_name);
DestroyGamepadImage(image);
DestroyGamepadDisplay(gamepad_elements);
DestroyGamepadTypeDisplay(gamepad_type);
DestroyJoystickDisplay(joystick_elements);
DestroyGamepadButton(setup_mapping_button);
DestroyGamepadButton(done_mapping_button);
DestroyGamepadButton(cancel_button);
DestroyGamepadButton(clear_button);
DestroyGamepadButton(copy_button);
DestroyGamepadButton(paste_button);
SDLTest_CleanupTextDrawing();
SDL_DestroyRenderer(screen);
SDL_DestroyWindow(window);
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD);
SDL_Quit();
SDLTest_CommonDestroyState(state);
return 0;
}

View File

@ -10,24 +10,11 @@
freely.
*/
#include <stdlib.h>
#include <SDL3/SDL_test_common.h>
#include <SDL3/SDL_main.h>
static SDLTest_CommonState *state;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
SDLTest_CommonQuit(state);
/* Let 'main()' return normally */
if (rc != 0) {
exit(rc);
}
}
int main(int argc, char *argv[])
{
int i, done;
@ -35,6 +22,7 @@ int main(int argc, char *argv[])
SDL_bool is_hover = SDL_FALSE;
float x = 0.0f, y = 0.0f;
unsigned int windowID = 0;
int return_code = -1;
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
@ -58,12 +46,14 @@ int main(int argc, char *argv[])
}
if (consumed < 0) {
SDLTest_CommonLogUsage(state, argv[0], NULL);
quit(1);
return_code = 1;
goto quit;
}
i += consumed;
}
if (!SDLTest_CommonInit(state)) {
quit(2);
return_code = 1;
goto quit;
}
@ -114,7 +104,8 @@ int main(int argc, char *argv[])
SDL_Delay(16);
}
quit(0);
/* keep the compiler happy ... */
return 0;
return_code = 0;
quit:
SDLTest_CommonQuit(state);
return return_code;
}

View File

@ -369,6 +369,7 @@ int main(int argc, char *argv[])
SDL_RWclose(rwops);
SDL_Log("test5 OK\n");
cleanup();
SDL_Quit();
SDLTest_CommonDestroyState(state);
return 0; /* all ok */
}

View File

@ -212,6 +212,12 @@ int main(int argc, char *argv[])
MoveSprites(renderer, sprite);
}
SDL_DestroyTexture(sprite);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_free(positions);
SDL_free(velocities);
quit(0);
return 0; /* to prevent compiler warning */

View File

@ -388,6 +388,15 @@ ret:
/* Destroy the window. */
SDL_DestroyWindow(window);
if (g_bitmap) {
SDL_free(g_bitmap);
g_bitmap = NULL;
}
if (g_shape_surface) {
SDL_DestroySurface(g_shape_surface);
g_shape_surface = NULL;
}
SDL_Quit();
SDLTest_CommonDestroyState(state);

View File

@ -35,17 +35,6 @@ static int sprite_w, sprite_h;
static SDL_Renderer *renderer;
static int done;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
SDL_Quit();
/* Let 'main()' return normally */
if (rc != 0) {
exit(rc);
}
}
static void MoveSprites(void)
{
int i;
@ -100,7 +89,8 @@ static void loop(void)
int main(int argc, char *argv[])
{
SDL_Window *window;
SDL_Window *window = NULL;
int return_code = -1;
int i;
/* Enable standard application logging */
@ -108,17 +98,24 @@ int main(int argc, char *argv[])
if (argc > 1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "USAGE: %s\n", argv[0]);
quit(1);
return_code = 1;
goto quit;
}
if (SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer) < 0) {
quit(2);
return_code = 2;
goto quit;
}
if (SDL_SetWindowTitle(window, argv[0]) < 0) {
SDL_Log("SDL_SetWindowTitle: %s", SDL_GetError());
}
sprite = LoadTexture(renderer, "icon.bmp", SDL_TRUE, &sprite_w, &sprite_h);
if (sprite == NULL) {
quit(2);
return_code = 3;
goto quit;
}
/* Initialize the sprite positions */
@ -146,7 +143,10 @@ int main(int argc, char *argv[])
loop();
}
#endif
quit(0);
return 0; /* to prevent compiler warning */
return_code = 0;
quit:
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return return_code;
}

View File

@ -10,8 +10,6 @@
freely.
*/
#include <stdlib.h>
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#endif
@ -42,17 +40,6 @@ static SDL_Cursor *cursor = NULL;
static SDL_bool relative_mode = SDL_FALSE;
static const SDL_DisplayMode *highlighted_mode = NULL;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
SDLTest_CommonQuit(state);
/* Let 'main()' return normally */
if (rc != 0) {
exit(rc);
}
}
/* Draws the modes menu, and stores the mode index under the mouse in highlighted_mode */
static void
draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
@ -298,7 +285,7 @@ int main(int argc, char *argv[])
#endif
SDL_DestroyCursor(cursor);
quit(0);
/* keep the compiler happy ... */
SDLTest_CleanupTextDrawing();
SDLTest_CommonQuit(state);
return 0;
}

View File

@ -243,6 +243,7 @@ int main(int argc, char **argv)
char *filename = NULL;
SDL_Surface *original;
SDL_Surface *converted;
SDL_Surface *bmp;
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *output[3];
@ -368,7 +369,9 @@ int main(int argc, char **argv)
}
filename = GetResourceFilename(filename, "testyuv.bmp");
original = SDL_ConvertSurfaceFormat(SDL_LoadBMP(filename), SDL_PIXELFORMAT_RGB24);
bmp = SDL_LoadBMP(filename);
original = SDL_ConvertSurfaceFormat(bmp, SDL_PIXELFORMAT_RGB24);
SDL_DestroySurface(bmp);
if (original == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
return 3;
@ -481,7 +484,13 @@ int main(int argc, char **argv)
SDL_Delay(10);
}
}
SDL_free(raw_yuv);
SDL_free(filename);
SDL_DestroySurface(original);
SDL_DestroySurface(converted);
SDLTest_CleanupTextDrawing();
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
SDLTest_CommonDestroyState(state);
return 0;