Skip to content

Commit c9f52b5

Browse files
committed
vdisp/sdl3: remove leaks if init fails
not much important but reported by Coverity (CID 899144)
1 parent 45e2cdb commit c9f52b5

1 file changed

Lines changed: 17 additions & 18 deletions

File tree

src/video_display/sdl3.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,16 @@ display_sdl3_init(struct module *parent, const char *fmt, unsigned int flags)
10111011
s->x = s->y = SDL_WINDOWPOS_UNDEFINED;
10121012
s->vsync = true;
10131013
s->hints = dictionary_init();
1014+
s->free_frame_queue = simple_linked_list_init();
1015+
1016+
module_init_default(&s->mod);
1017+
s->mod.new_message = display_sdl3_new_message;
1018+
s->mod.cls = MODULE_CLASS_DATA;
1019+
module_register(&s->mod, parent);
1020+
1021+
pthread_mutex_init(&s->lock, NULL);
1022+
pthread_cond_init(&s->frame_consumed_cv, NULL);
1023+
pthread_cond_init(&s->reconfigured_cv, NULL);
10141024

10151025
if (fmt == NULL) {
10161026
fmt = "";
@@ -1031,7 +1041,7 @@ display_sdl3_init(struct module *parent, const char *fmt, unsigned int flags)
10311041
s->fs = true;
10321042
} else if (IS_PREFIX(tok, "help") || strcmp(tok, "fullhelp") == 0) {
10331043
show_help(driver, strcmp(tok, "fullhelp") == 0);
1034-
free(s);
1044+
display_sdl3_done(s);
10351045
return INIT_NOERR;
10361046
} else if (IS_PREFIX(tok, "novsync")) {
10371047
s->vsync = false;
@@ -1042,7 +1052,7 @@ display_sdl3_init(struct module *parent, const char *fmt, unsigned int flags)
10421052
} else if (IS_KEY_PREFIX(tok, "fixed_size") ||
10431053
IS_KEY_PREFIX(tok, "size")) {
10441054
if (!set_size(s, tok)) {
1045-
free(s);
1055+
display_sdl3_done(s);
10461056
return NULL;
10471057
}
10481058
} else if (strcmp(tok, "fixed_size") == 0) {
@@ -1055,15 +1065,15 @@ display_sdl3_init(struct module *parent, const char *fmt, unsigned int flags)
10551065
if (sscanf(strchr(tok, '=') + 1, "%i", &f) != 1) {
10561066
log_msg(LOG_LEVEL_ERROR,
10571067
"Wrong window_flags: %s\n", tok);
1058-
free(s);
1068+
display_sdl3_done(s);
10591069
return NULL;
10601070
}
10611071
s->window_flags |= f;
10621072
} else if (IS_KEY_PREFIX(tok, "position")) {
10631073
tok = strchr(tok, '=') + 1;
10641074
if (strchr(tok, ',') == NULL) {
10651075
MSG(ERROR, "position: %s\n", tok);
1066-
free(s);
1076+
display_sdl3_done(s);
10671077
return NULL;
10681078
}
10691079
s->x = atoi(tok);
@@ -1085,7 +1095,7 @@ display_sdl3_init(struct module *parent, const char *fmt, unsigned int flags)
10851095
s->show_cursor = true;
10861096
} else {
10871097
MSG(ERROR, "Wrong option: %s\n", tok);
1088-
free(s);
1098+
display_sdl3_done(s);
10891099
return NULL;
10901100
}
10911101
tmp = NULL;
@@ -1111,13 +1121,13 @@ display_sdl3_init(struct module *parent, const char *fmt, unsigned int flags)
11111121
if (!SDL_InitSubSystem(SDL_INIT_VIDEO)) {
11121122
MSG(ERROR, "Unable to initialize SDL3 video: %s\n",
11131123
SDL_GetError());
1114-
free(s);
1124+
display_sdl3_done(s);
11151125
return NULL;
11161126
}
11171127
if (!SDL_InitSubSystem(SDL_INIT_EVENTS)) {
11181128
MSG(ERROR, "Unable to initialize SDL3 events: %s\n",
11191129
SDL_GetError());
1120-
free(s);
1130+
display_sdl3_done(s);
11211131
return NULL;
11221132
}
11231133
MSG(NOTICE, "Using driver: %s\n", SDL_GetCurrentVideoDriver());
@@ -1127,22 +1137,11 @@ display_sdl3_init(struct module *parent, const char *fmt, unsigned int flags)
11271137
}
11281138
SDL_CHECK(SDL_DisableScreenSaver());
11291139

1130-
module_init_default(&s->mod);
1131-
s->mod.new_message = display_sdl3_new_message;
1132-
s->mod.cls = MODULE_CLASS_DATA;
1133-
module_register(&s->mod, parent);
1134-
1135-
pthread_mutex_init(&s->lock, NULL);
1136-
pthread_cond_init(&s->frame_consumed_cv, NULL);
1137-
pthread_cond_init(&s->reconfigured_cv, NULL);
1138-
11391140
s->sdl_user_new_frame_event = SDL_RegisterEvents(3);
11401141
assert(s->sdl_user_new_frame_event != (Uint32) -1);
11411142
s->sdl_user_new_message_event = s->sdl_user_new_frame_event + 1;
11421143
s->sdl_user_reconfigure_event = s->sdl_user_new_frame_event + 2;
11431144

1144-
s->free_frame_queue = simple_linked_list_init();
1145-
11461145
for (unsigned int i = 0; i < sizeof keybindings / sizeof keybindings[0];
11471146
++i) {
11481147
if (keybindings[i].key ==

0 commit comments

Comments
 (0)