Fix some memory leaks and fallthrough errors picked up on by

Clang static code analyzer
This commit is contained in:
twinaphex 2020-06-07 16:15:35 +02:00
parent df8df6c18b
commit 98b847cad9
4 changed files with 71 additions and 50 deletions

View File

@ -7095,16 +7095,24 @@ static void *materialui_init(void **userdata, bool video_is_threaded)
unsigned width, height;
settings_t *settings = config_get_ptr();
materialui_handle_t *mui = NULL;
menu_handle_t *menu = (menu_handle_t*)calloc(1, sizeof(*menu));
static const char* const ticker_spacer = MUI_TICKER_SPACER;
menu_handle_t *menu = (menu_handle_t*)
calloc(1, sizeof(*menu));
if (!menu || !settings)
if (!menu)
return NULL;
if (!settings)
{
free(menu);
return NULL;
}
if (!gfx_display_init_first_driver(video_is_threaded))
goto error;
mui = (materialui_handle_t*)calloc(1, sizeof(materialui_handle_t));
mui = (materialui_handle_t*)
calloc(1, sizeof(materialui_handle_t));
if (!mui)
goto error;
@ -7122,7 +7130,8 @@ static void *materialui_init(void **userdata, bool video_is_threaded)
mui->last_width = width;
mui->last_height = height;
mui->last_scale_factor = gfx_display_get_dpi_scale(width, height);
mui->last_scale_factor = gfx_display_get_dpi_scale(
width, height);
mui->dip_base_unit_size = mui->last_scale_factor
* MUI_DIP_BASE_UNIT_SIZE;
@ -7143,7 +7152,8 @@ static void *materialui_init(void **userdata, bool video_is_threaded)
mui->menu_title[0] = '\0';
/* Set initial theme colours */
mui->color_theme = (enum materialui_color_theme)settings->uints.menu_materialui_color_theme;
mui->color_theme = (enum materialui_color_theme)
settings->uints.menu_materialui_color_theme;
materialui_prepare_colors(mui, (enum materialui_color_theme)mui->color_theme);
/* Initial ticker configuration */

View File

@ -1705,7 +1705,8 @@ static bool request_thumbnail(
return false;
}
static bool downscale_thumbnail(rgui_t *rgui, unsigned max_width, unsigned max_height,
static bool downscale_thumbnail(rgui_t *rgui,
unsigned max_width, unsigned max_height,
struct texture_image *image_src, struct texture_image *image_dst)
{
/* Determine output dimensions */
@ -1827,7 +1828,11 @@ static void process_thumbnail(rgui_t *rgui, thumbnail_t *thumbnail, uint32_t *qu
if ((image_src->width > thumbnail->max_width) || (image_src->height > thumbnail->max_height))
{
if (!downscale_thumbnail(rgui, thumbnail->max_width, thumbnail->max_height, image_src, &image_resampled))
{
if (image_resampled.pixels)
free(image_resampled.pixels);
return;
}
image = &image_resampled;
}
else

View File

@ -183,14 +183,16 @@ const char *get_user_language_iso639_1(bool limit)
break;
case RETRO_LANGUAGE_RUSSIAN:
voice = "ru";
break;
case RETRO_LANGUAGE_PERSIAN:
voice = "fa";
break;
case RETRO_LANGUAGE_HEBREW:
voice = "he";
break;
case RETRO_LANGUAGE_ASTURIAN:
voice = "ast";
break;
}
return voice;
}

View File

@ -273,7 +273,8 @@ static bool screenshot_dump(
struct retro_system_info system_info;
uint8_t *buf = NULL;
settings_t *settings = config_get_ptr();
screenshot_task_state_t *state = (screenshot_task_state_t*)calloc(1, sizeof(*state));
screenshot_task_state_t *state = (screenshot_task_state_t*)
calloc(1, sizeof(*state));
state->shotname[0] = '\0';
@ -319,7 +320,10 @@ static bool screenshot_dump(
if (path_is_empty(RARCH_PATH_CONTENT))
{
if (!core_get_system_info(&system_info))
{
free(state);
return false;
}
if (string_is_empty(system_info.library_name))
screenshot_name = "RetroArch";