Skip to content

Commit 6f9aebe

Browse files
committed
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.
1 parent 62aaf7e commit 6f9aebe

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

backend/sdl.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ twin_context_t *twin_sdl_init(int width, int height)
137137
SDL_WINDOW_SHOWN);
138138
if (!tx->win) {
139139
log_error("%s", SDL_GetError());
140-
goto bail;
140+
goto bail_sdl;
141141
}
142142

143143
tx->pixels = malloc(width * height * sizeof(*tx->pixels));
@@ -192,6 +192,8 @@ twin_context_t *twin_sdl_init(int width, int height)
192192
free(tx->pixels);
193193
bail_window:
194194
SDL_DestroyWindow(tx->win);
195+
bail_sdl:
196+
SDL_Quit();
195197
bail:
196198
free(ctx->priv);
197199
free(ctx);

0 commit comments

Comments
 (0)