From 6f9aebe14662ef806d2200b4dbf93e92e26722ca Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Sun, 19 Oct 2025 17:22:08 +0800 Subject: [PATCH] Prevent resource leak in SDL backend When twin_sdl_init() fails after successful SDL_Init() but before completion (e.g., SDL_CreateWindow fails), the SDL subsystem is not properly cleaned up, leaking system resources. The bail chain was missing SDL_Quit() cleanup. Error paths jumped directly to 'bail' label which only freed memory, leaving SDL initialized. --- backend/sdl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/sdl.c b/backend/sdl.c index a56eb18c..1536e8b4 100644 --- a/backend/sdl.c +++ b/backend/sdl.c @@ -137,7 +137,7 @@ twin_context_t *twin_sdl_init(int width, int height) SDL_WINDOW_SHOWN); if (!tx->win) { log_error("%s", SDL_GetError()); - goto bail; + goto bail_sdl; } tx->pixels = malloc(width * height * sizeof(*tx->pixels)); @@ -192,6 +192,8 @@ twin_context_t *twin_sdl_init(int width, int height) free(tx->pixels); bail_window: SDL_DestroyWindow(tx->win); +bail_sdl: + SDL_Quit(); bail: free(ctx->priv); free(ctx);