Move path variables off heap size; prevent potential memory

fragmentation
This commit is contained in:
twinaphex 2020-08-18 12:44:14 +02:00
parent fe28f17eeb
commit ad7db2e2b8
9 changed files with 261 additions and 536 deletions

View File

@ -2498,13 +2498,16 @@ void config_set_defaults(void *data)
g_defaults.dirs[DEFAULT_DIR_MENU_CONFIG]); g_defaults.dirs[DEFAULT_DIR_MENU_CONFIG]);
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
{ {
char *config_file_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char config_file_path[PATH_MAX_LENGTH];
size_t config_file_path_size = PATH_MAX_LENGTH * sizeof(char);
fill_pathname_join(config_file_path, settings->paths.directory_menu_config, file_path_str(FILE_PATH_MAIN_CONFIG), config_file_path_size); config_file_path[0] = '\0';
fill_pathname_join(config_file_path,
settings->paths.directory_menu_config,
file_path_str(FILE_PATH_MAIN_CONFIG),
sizeof(config_file_path));
path_set(RARCH_PATH_CONFIG, path_set(RARCH_PATH_CONFIG,
config_file_path); config_file_path);
free(config_file_path);
} }
#endif #endif
} }
@ -2548,15 +2551,14 @@ void config_set_defaults(void *data)
if (!string_is_empty(g_defaults.path_config)) if (!string_is_empty(g_defaults.path_config))
{ {
char *temp_str = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char temp_str[PATH_MAX_LENGTH];
temp_str[0] = '\0'; temp_str[0] = '\0';
fill_pathname_expand_special(temp_str, fill_pathname_expand_special(temp_str,
g_defaults.path_config, g_defaults.path_config,
PATH_MAX_LENGTH * sizeof(char)); sizeof(temp_str));
path_set(RARCH_PATH_CONFIG, temp_str); path_set(RARCH_PATH_CONFIG, temp_str);
free(temp_str);
} }
configuration_set_string(settings, configuration_set_string(settings,
@ -2646,37 +2648,33 @@ static bool check_menu_driver_compatibility(settings_t *settings)
**/ **/
static config_file_t *open_default_config_file(void) static config_file_t *open_default_config_file(void)
{ {
char application_data[PATH_MAX_LENGTH];
char conf_path[PATH_MAX_LENGTH];
char app_path[PATH_MAX_LENGTH];
bool has_application_data = false; bool has_application_data = false;
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
char *application_data = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
char *conf_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
char *app_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
config_file_t *conf = NULL; config_file_t *conf = NULL;
(void)has_application_data;
(void)path_size;
application_data[0] = conf_path[0] = app_path[0] = '\0'; application_data[0] = conf_path[0] = app_path[0] = '\0';
#if defined(_WIN32) && !defined(_XBOX) #if defined(_WIN32) && !defined(_XBOX)
#if defined(__WINRT__) || defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP #if defined(__WINRT__) || defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
/* On UWP, the app install directory is not writable so use the writable LocalState dir instead */ /* On UWP, the app install directory is not writable so use the writable LocalState dir instead */
fill_pathname_home_dir(app_path, path_size); fill_pathname_home_dir(app_path, sizeof(app_path));
#else #else
fill_pathname_application_dir(app_path, path_size); fill_pathname_application_dir(app_path, sizeof(app_path));
#endif #endif
fill_pathname_resolve_relative(conf_path, app_path, fill_pathname_resolve_relative(conf_path, app_path,
file_path_str(FILE_PATH_MAIN_CONFIG), path_size); file_path_str(FILE_PATH_MAIN_CONFIG), sizeof(conf_path));
conf = config_file_new_from_path_to_string(conf_path); conf = config_file_new_from_path_to_string(conf_path);
if (!conf) if (!conf)
{ {
if (fill_pathname_application_data(application_data, if (fill_pathname_application_data(application_data,
path_size)) sizeof(application_data)))
{ {
fill_pathname_join(conf_path, application_data, fill_pathname_join(conf_path, application_data,
file_path_str(FILE_PATH_MAIN_CONFIG), path_size); file_path_str(FILE_PATH_MAIN_CONFIG), sizeof(conf_path));
conf = config_file_new_from_path_to_string(conf_path); conf = config_file_new_from_path_to_string(conf_path);
} }
} }
@ -2693,7 +2691,7 @@ static config_file_t *open_default_config_file(void)
/* Since this is a clean config file, we can /* Since this is a clean config file, we can
* safely use config_save_on_exit. */ * safely use config_save_on_exit. */
fill_pathname_resolve_relative(conf_path, app_path, fill_pathname_resolve_relative(conf_path, app_path,
file_path_str(FILE_PATH_MAIN_CONFIG), path_size); file_path_str(FILE_PATH_MAIN_CONFIG), sizeof(conf_path));
config_set_bool(conf, "config_save_on_exit", true); config_set_bool(conf, "config_save_on_exit", true);
saved = config_file_write(conf, conf_path, true); saved = config_file_write(conf, conf_path, true);
} }
@ -2710,16 +2708,16 @@ static config_file_t *open_default_config_file(void)
} }
#elif defined(OSX) #elif defined(OSX)
if (!fill_pathname_application_data(application_data, if (!fill_pathname_application_data(application_data,
path_size)) sizeof(application_data)))
goto error; goto error;
/* Group config file with menu configs, remaps, etc: */ /* Group config file with menu configs, remaps, etc: */
strlcat(application_data, "/config", path_size); strlcat(application_data, "/config", sizeof(application_data));
path_mkdir(application_data); path_mkdir(application_data);
fill_pathname_join(conf_path, application_data, fill_pathname_join(conf_path, application_data,
file_path_str(FILE_PATH_MAIN_CONFIG), path_size); file_path_str(FILE_PATH_MAIN_CONFIG), sizeof(conf_path));
conf = config_file_new_from_path_to_string(conf_path); conf = config_file_new_from_path_to_string(conf_path);
if (!conf) if (!conf)
@ -2746,12 +2744,12 @@ static config_file_t *open_default_config_file(void)
#elif !defined(RARCH_CONSOLE) #elif !defined(RARCH_CONSOLE)
has_application_data = has_application_data =
fill_pathname_application_data(application_data, fill_pathname_application_data(application_data,
path_size); sizeof(application_data));
if (has_application_data) if (has_application_data)
{ {
fill_pathname_join(conf_path, application_data, fill_pathname_join(conf_path, application_data,
file_path_str(FILE_PATH_MAIN_CONFIG), path_size); file_path_str(FILE_PATH_MAIN_CONFIG), sizeof(conf_path));
RARCH_LOG("Looking for config in: \"%s\".\n", conf_path); RARCH_LOG("Looking for config in: \"%s\".\n", conf_path);
conf = config_file_new_from_path_to_string(conf_path); conf = config_file_new_from_path_to_string(conf_path);
} }
@ -2760,7 +2758,7 @@ static config_file_t *open_default_config_file(void)
if (!conf && getenv("HOME")) if (!conf && getenv("HOME"))
{ {
fill_pathname_join(conf_path, getenv("HOME"), fill_pathname_join(conf_path, getenv("HOME"),
".retroarch.cfg", path_size); ".retroarch.cfg", sizeof(conf_path));
RARCH_LOG("Looking for config in: \"%s\".\n", conf_path); RARCH_LOG("Looking for config in: \"%s\".\n", conf_path);
conf = config_file_new_from_path_to_string(conf_path); conf = config_file_new_from_path_to_string(conf_path);
} }
@ -2768,25 +2766,21 @@ static config_file_t *open_default_config_file(void)
if (!conf && has_application_data) if (!conf && has_application_data)
{ {
bool dir_created = false; bool dir_created = false;
char *basedir = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char basedir[PATH_MAX_LENGTH];
basedir[0] = '\0'; basedir[0] = '\0';
/* Try to create a new config file. */ /* Try to create a new config file. */
strlcpy(conf_path, application_data, path_size); fill_pathname_basedir(basedir, application_data, sizeof(basedir));
fill_pathname_join(conf_path, application_data,
fill_pathname_basedir(basedir, conf_path, path_size); file_path_str(FILE_PATH_MAIN_CONFIG), sizeof(conf_path));
fill_pathname_join(conf_path, conf_path,
file_path_str(FILE_PATH_MAIN_CONFIG), path_size);
dir_created = path_mkdir(basedir); dir_created = path_mkdir(basedir);
free(basedir);
if (dir_created) if (dir_created)
{ {
char *skeleton_conf = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char skeleton_conf[PATH_MAX_LENGTH];
bool saved = false; bool saved = false;
skeleton_conf[0] = '\0'; skeleton_conf[0] = '\0';
@ -2794,7 +2788,7 @@ static config_file_t *open_default_config_file(void)
/* Build a retroarch.cfg path from the /* Build a retroarch.cfg path from the
* global config directory (/etc). */ * global config directory (/etc). */
fill_pathname_join(skeleton_conf, GLOBAL_CONFIG_DIR, fill_pathname_join(skeleton_conf, GLOBAL_CONFIG_DIR,
file_path_str(FILE_PATH_MAIN_CONFIG), path_size); file_path_str(FILE_PATH_MAIN_CONFIG), sizeof(skeleton_conf));
conf = config_file_new_from_path_to_string(skeleton_conf); conf = config_file_new_from_path_to_string(skeleton_conf);
if (conf) if (conf)
@ -2802,8 +2796,6 @@ static config_file_t *open_default_config_file(void)
else else
conf = config_file_new_alloc(); conf = config_file_new_alloc();
free(skeleton_conf);
if (conf) if (conf)
{ {
/* Since this is a clean config file, we can /* Since this is a clean config file, we can
@ -2815,35 +2807,27 @@ static config_file_t *open_default_config_file(void)
if (!saved) if (!saved)
{ {
/* WARN here to make sure user has a good chance of seeing it. */ /* WARN here to make sure user has a good chance of seeing it. */
RARCH_ERR("Failed to create new config file in: \"%s\".\n", conf_path); RARCH_ERR("Failed to create new config file in: \"%s\".\n",
conf_path);
goto error; goto error;
} }
RARCH_WARN("Config: Created new config file in: \"%s\".\n", conf_path); RARCH_WARN("Config: Created new config file in: \"%s\".\n",
conf_path);
} }
} }
#endif #endif
(void)application_data;
(void)conf_path;
(void)app_path;
if (!conf) if (!conf)
goto error; goto error;
path_set(RARCH_PATH_CONFIG, conf_path); path_set(RARCH_PATH_CONFIG, conf_path);
free(application_data);
free(conf_path);
free(app_path);
return conf; return conf;
error: error:
if (conf) if (conf)
config_file_free(conf); config_file_free(conf);
free(application_data);
free(conf_path);
free(app_path);
return NULL; return NULL;
} }
@ -2892,8 +2876,7 @@ static bool config_load_file(global_t *global,
const char *path, settings_t *settings) const char *path, settings_t *settings)
{ {
unsigned i; unsigned i;
size_t path_size = PATH_MAX_LENGTH * sizeof(char); char tmp_str[PATH_MAX_LENGTH];
char *tmp_str = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
bool ret = false; bool ret = false;
unsigned tmp_uint = 0; unsigned tmp_uint = 0;
bool tmp_bool = false; bool tmp_bool = false;
@ -2931,13 +2914,13 @@ static bool config_load_file(global_t *global,
{ {
/* Don't destroy append_config_path, store in temporary /* Don't destroy append_config_path, store in temporary
* variable. */ * variable. */
char *tmp_append_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char tmp_append_path[PATH_MAX_LENGTH];
const char *extra_path = NULL; const char *extra_path = NULL;
tmp_append_path[0] = '\0'; tmp_append_path[0] = '\0';
strlcpy(tmp_append_path, path_get(RARCH_PATH_CONFIG_APPEND), strlcpy(tmp_append_path, path_get(RARCH_PATH_CONFIG_APPEND),
path_size); sizeof(tmp_append_path));
extra_path = strtok_r(tmp_append_path, "|", &save); extra_path = strtok_r(tmp_append_path, "|", &save);
while (extra_path) while (extra_path)
@ -2950,8 +2933,6 @@ static bool config_load_file(global_t *global,
RARCH_ERR("Config: failed to append config \"%s\"\n", extra_path); RARCH_ERR("Config: failed to append config \"%s\"\n", extra_path);
extra_path = strtok_r(NULL, "|", &save); extra_path = strtok_r(NULL, "|", &save);
} }
free(tmp_append_path);
} }
#if 0 #if 0
@ -3099,16 +3080,16 @@ static bool config_load_file(global_t *global,
{ {
if (!path_settings[i].handle) if (!path_settings[i].handle)
continue; continue;
if (config_get_path(conf, path_settings[i].ident, tmp_str, path_size)) if (config_get_path(conf, path_settings[i].ident, tmp_str, sizeof(tmp_str)))
strlcpy(path_settings[i].ptr, tmp_str, PATH_MAX_LENGTH); strlcpy(path_settings[i].ptr, tmp_str, PATH_MAX_LENGTH);
} }
if (config_get_path(conf, "libretro_directory", tmp_str, path_size)) if (config_get_path(conf, "libretro_directory", tmp_str, sizeof(tmp_str)))
configuration_set_string(settings, configuration_set_string(settings,
settings->paths.directory_libretro, tmp_str); settings->paths.directory_libretro, tmp_str);
#ifndef HAVE_DYNAMIC #ifndef HAVE_DYNAMIC
if (config_get_path(conf, "libretro_path", tmp_str, path_size)) if (config_get_path(conf, "libretro_path", tmp_str, sizeof(tmp_str)))
path_set(RARCH_PATH_CORE, tmp_str); path_set(RARCH_PATH_CORE, tmp_str);
#endif #endif
@ -3318,7 +3299,7 @@ static bool config_load_file(global_t *global,
#endif #endif
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_SAVE_PATH, NULL) && if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_SAVE_PATH, NULL) &&
config_get_path(conf, "savefile_directory", tmp_str, path_size)) config_get_path(conf, "savefile_directory", tmp_str, sizeof(tmp_str)))
{ {
if (string_is_equal(tmp_str, "default")) if (string_is_equal(tmp_str, "default"))
dir_set(RARCH_DIR_SAVEFILE, g_defaults.dirs[DEFAULT_DIR_SRAM]); dir_set(RARCH_DIR_SAVEFILE, g_defaults.dirs[DEFAULT_DIR_SRAM]);
@ -3342,7 +3323,7 @@ static bool config_load_file(global_t *global,
} }
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_STATE_PATH, NULL) && if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_STATE_PATH, NULL) &&
config_get_path(conf, "savestate_directory", tmp_str, path_size)) config_get_path(conf, "savestate_directory", tmp_str, sizeof(tmp_str)))
{ {
if (string_is_equal(tmp_str, "default")) if (string_is_equal(tmp_str, "default"))
dir_set(RARCH_DIR_SAVESTATE, g_defaults.dirs[DEFAULT_DIR_SAVESTATE]); dir_set(RARCH_DIR_SAVESTATE, g_defaults.dirs[DEFAULT_DIR_SAVESTATE]);
@ -3417,7 +3398,6 @@ end:
free(path_settings); free(path_settings);
if (size_settings) if (size_settings)
free(size_settings); free(size_settings);
free(tmp_str);
return ret; return ret;
} }
@ -3442,12 +3422,12 @@ end:
*/ */
bool config_load_override(void *data) bool config_load_override(void *data)
{ {
size_t path_size = PATH_MAX_LENGTH * sizeof(char); char buf[PATH_MAX_LENGTH];
char *buf = NULL; char core_path[PATH_MAX_LENGTH];
char *core_path = NULL; char game_path[PATH_MAX_LENGTH];
char *game_path = NULL; char content_path[PATH_MAX_LENGTH];
char *content_path = NULL; char content_dir_name[PATH_MAX_LENGTH];
char *config_directory = NULL; char config_directory[PATH_MAX_LENGTH];
bool should_append = false; bool should_append = false;
rarch_system_info_t *system = (rarch_system_info_t*)data; rarch_system_info_t *system = (rarch_system_info_t*)data;
const char *core_name = system ? const char *core_name = system ?
@ -3455,7 +3435,6 @@ bool config_load_override(void *data)
const char *rarch_path_basename = path_get(RARCH_PATH_BASENAME); const char *rarch_path_basename = path_get(RARCH_PATH_BASENAME);
const char *game_name = path_basename(rarch_path_basename); const char *game_name = path_basename(rarch_path_basename);
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
char content_dir_name[PATH_MAX_LENGTH];
if (!string_is_empty(rarch_path_basename)) if (!string_is_empty(rarch_path_basename))
fill_pathname_parent_dir_name(content_dir_name, fill_pathname_parent_dir_name(content_dir_name,
@ -3464,41 +3443,30 @@ bool config_load_override(void *data)
if (string_is_empty(core_name) || string_is_empty(game_name)) if (string_is_empty(core_name) || string_is_empty(game_name))
return false; return false;
game_path = (char*) config_directory[0] = core_path[0] = game_path[0] = buf[0] = '\0';
malloc(PATH_MAX_LENGTH * sizeof(char));
core_path = (char*)
malloc(PATH_MAX_LENGTH * sizeof(char));
content_path = (char*)
malloc(PATH_MAX_LENGTH * sizeof(char));
buf = (char*)
malloc(PATH_MAX_LENGTH * sizeof(char));
config_directory = (char*)
malloc(PATH_MAX_LENGTH * sizeof(char));
config_directory[0] = core_path[0] = game_path[0] = '\0';
fill_pathname_application_special(config_directory, path_size, fill_pathname_application_special(config_directory, sizeof(config_directory),
APPLICATION_SPECIAL_DIRECTORY_CONFIG); APPLICATION_SPECIAL_DIRECTORY_CONFIG);
/* Concatenate strings into full paths for core_path, game_path, content_path */ /* Concatenate strings into full paths for core_path, game_path,
* content_path */
fill_pathname_join_special_ext(game_path, fill_pathname_join_special_ext(game_path,
config_directory, core_name, config_directory, core_name,
game_name, game_name,
".cfg", ".cfg",
path_size); sizeof(game_path));
fill_pathname_join_special_ext(content_path, fill_pathname_join_special_ext(content_path,
config_directory, core_name, config_directory, core_name,
content_dir_name, content_dir_name,
".cfg", ".cfg",
path_size); sizeof(content_path));
fill_pathname_join_special_ext(core_path, fill_pathname_join_special_ext(core_path,
config_directory, core_name, config_directory, core_name,
core_name, core_name,
".cfg", ".cfg",
path_size); sizeof(core_path));
free(config_directory);
/* per-core overrides */ /* per-core overrides */
/* Create a new config file from core_path */ /* Create a new config file from core_path */
@ -3519,7 +3487,7 @@ bool config_load_override(void *data)
/* Create a new config file from content_path */ /* Create a new config file from content_path */
if (config_file_exists(content_path)) if (config_file_exists(content_path))
{ {
char *temp_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char temp_path[PATH_MAX_LENGTH];
temp_path[0] = '\0'; temp_path[0] = '\0';
@ -3529,17 +3497,15 @@ bool config_load_override(void *data)
if (should_append) if (should_append)
{ {
RARCH_LOG("[Overrides]: Content dir-specific overrides stacking on top of previous overrides.\n"); RARCH_LOG("[Overrides]: Content dir-specific overrides stacking on top of previous overrides.\n");
strlcpy(temp_path, path_get(RARCH_PATH_CONFIG_APPEND), path_size); strlcpy(temp_path, path_get(RARCH_PATH_CONFIG_APPEND), sizeof(temp_path));
strlcat(temp_path, "|", path_size); strlcat(temp_path, "|", sizeof(temp_path));
strlcat(temp_path, content_path, path_size); strlcat(temp_path, content_path, sizeof(temp_path));
} }
else else
strlcpy(temp_path, content_path, path_size); strlcpy(temp_path, content_path, sizeof(temp_path));
path_set(RARCH_PATH_CONFIG_APPEND, temp_path); path_set(RARCH_PATH_CONFIG_APPEND, temp_path);
free(temp_path);
should_append = true; should_append = true;
} }
else else
@ -3550,7 +3516,7 @@ bool config_load_override(void *data)
/* Create a new config file from game_path */ /* Create a new config file from game_path */
if (config_file_exists(game_path)) if (config_file_exists(game_path))
{ {
char *temp_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char temp_path[PATH_MAX_LENGTH];
temp_path[0] = '\0'; temp_path[0] = '\0';
@ -3560,17 +3526,15 @@ bool config_load_override(void *data)
if (should_append) if (should_append)
{ {
RARCH_LOG("[Overrides]: game-specific overrides stacking on top of previous overrides\n"); RARCH_LOG("[Overrides]: game-specific overrides stacking on top of previous overrides\n");
strlcpy(temp_path, path_get(RARCH_PATH_CONFIG_APPEND), path_size); strlcpy(temp_path, path_get(RARCH_PATH_CONFIG_APPEND), sizeof(temp_path));
strlcat(temp_path, "|", path_size); strlcat(temp_path, "|", sizeof(temp_path));
strlcat(temp_path, game_path, path_size); strlcat(temp_path, game_path, sizeof(temp_path));
} }
else else
strlcpy(temp_path, game_path, path_size); strlcpy(temp_path, game_path, sizeof(temp_path));
path_set(RARCH_PATH_CONFIG_APPEND, temp_path); path_set(RARCH_PATH_CONFIG_APPEND, temp_path);
free(temp_path);
should_append = true; should_append = true;
} }
else else
@ -3578,15 +3542,13 @@ bool config_load_override(void *data)
game_path); game_path);
if (!should_append) if (!should_append)
goto error; return false;
/* Re-load the configuration with any overrides /* Re-load the configuration with any overrides
* that might have been found */ * that might have been found */
buf[0] = '\0';
/* Store the libretro_path we're using since it will be /* Store the libretro_path we're using since it will be
* overwritten by the override when reloading. */ * overwritten by the override when reloading. */
strlcpy(buf, path_get(RARCH_PATH_CORE), path_size); strlcpy(buf, path_get(RARCH_PATH_CORE), sizeof(buf));
/* Toggle has_save_path to false so it resets */ /* Toggle has_save_path to false so it resets */
retroarch_override_setting_unset(RARCH_OVERRIDE_SETTING_STATE_PATH, NULL); retroarch_override_setting_unset(RARCH_OVERRIDE_SETTING_STATE_PATH, NULL);
@ -3594,7 +3556,7 @@ bool config_load_override(void *data)
if (!config_load_file(global_get_ptr(), if (!config_load_file(global_get_ptr(),
path_get(RARCH_PATH_CONFIG), settings)) path_get(RARCH_PATH_CONFIG), settings))
goto error; return false;
/* Restore the libretro_path we're using /* Restore the libretro_path we're using
* since it will be overwritten by the override when reloading. */ * since it will be overwritten by the override when reloading. */
@ -3610,18 +3572,7 @@ bool config_load_override(void *data)
path_clear(RARCH_PATH_CONFIG_APPEND); path_clear(RARCH_PATH_CONFIG_APPEND);
free(buf);
free(core_path);
free(content_path);
free(game_path);
return true; return true;
error:
free(buf);
free(core_path);
free(content_path);
free(game_path);
return false;
} }
/** /**
@ -3669,12 +3620,16 @@ bool config_unload_override(void)
bool config_load_remap(const char *directory_input_remapping, bool config_load_remap(const char *directory_input_remapping,
void *data) void *data)
{ {
size_t path_size = PATH_MAX_LENGTH * sizeof(char); char content_dir_name[PATH_MAX_LENGTH];
/* path to the directory containing retroarch.cfg (prefix) */
char remap_directory[PATH_MAX_LENGTH];
/* final path for core-specific configuration (prefix+suffix) */
char core_path[PATH_MAX_LENGTH];
/* final path for game-specific configuration (prefix+suffix) */
char game_path[PATH_MAX_LENGTH];
/* final path for content-dir-specific configuration (prefix+suffix) */
char content_path[PATH_MAX_LENGTH];
config_file_t *new_conf = NULL; config_file_t *new_conf = NULL;
char *remap_directory = NULL;
char *core_path = NULL;
char *game_path = NULL;
char *content_path = NULL;
rarch_system_info_t *system = (rarch_system_info_t*)data; rarch_system_info_t *system = (rarch_system_info_t*)data;
const char *core_name = system ? system->info.library_name : NULL; const char *core_name = system ? system->info.library_name : NULL;
const char *rarch_path_basename = path_get(RARCH_PATH_BASENAME); const char *rarch_path_basename = path_get(RARCH_PATH_BASENAME);
@ -3682,7 +3637,6 @@ bool config_load_remap(const char *directory_input_remapping,
enum msg_hash_enums msg_remap_loaded = MSG_GAME_REMAP_FILE_LOADED; enum msg_hash_enums msg_remap_loaded = MSG_GAME_REMAP_FILE_LOADED;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
bool notification_show_remap_load = settings->bools.notification_show_remap_load; bool notification_show_remap_load = settings->bools.notification_show_remap_load;
char content_dir_name[PATH_MAX_LENGTH];
if (string_is_empty(core_name) || string_is_empty(game_name)) if (string_is_empty(core_name) || string_is_empty(game_name))
return false; return false;
@ -3696,21 +3650,10 @@ bool config_load_remap(const char *directory_input_remapping,
fill_pathname_parent_dir_name(content_dir_name, fill_pathname_parent_dir_name(content_dir_name,
rarch_path_basename, sizeof(content_dir_name)); rarch_path_basename, sizeof(content_dir_name));
/* path to the directory containing retroarch.cfg (prefix) */
remap_directory = (char*)
malloc(PATH_MAX_LENGTH * sizeof(char));
/* final path for core-specific configuration (prefix+suffix) */
core_path = (char*)
malloc(PATH_MAX_LENGTH * sizeof(char));
/* final path for game-specific configuration (prefix+suffix) */
game_path = (char*)
malloc(PATH_MAX_LENGTH * sizeof(char));
/* final path for content-dir-specific configuration (prefix+suffix) */
content_path = (char*)
malloc(PATH_MAX_LENGTH * sizeof(char));
remap_directory[0] = core_path[0] = game_path[0] = '\0'; remap_directory[0] = core_path[0] = game_path[0] = '\0';
strlcpy(remap_directory, directory_input_remapping, path_size); strlcpy(remap_directory,
directory_input_remapping, sizeof(remap_directory));
RARCH_LOG("[Remaps]: remap directory: %s\n", remap_directory); RARCH_LOG("[Remaps]: remap directory: %s\n", remap_directory);
/* Concatenate strings into full paths for core_path, game_path */ /* Concatenate strings into full paths for core_path, game_path */
@ -3718,19 +3661,19 @@ bool config_load_remap(const char *directory_input_remapping,
remap_directory, core_name, remap_directory, core_name,
core_name, core_name,
".rmp", ".rmp",
path_size); sizeof(core_path));
fill_pathname_join_special_ext(content_path, fill_pathname_join_special_ext(content_path,
remap_directory, core_name, remap_directory, core_name,
content_dir_name, content_dir_name,
".rmp", ".rmp",
path_size); sizeof(content_path));
fill_pathname_join_special_ext(game_path, fill_pathname_join_special_ext(game_path,
remap_directory, core_name, remap_directory, core_name,
game_name, game_name,
".rmp", ".rmp",
path_size); sizeof(game_path));
#ifdef HAVE_CONFIGFILE #ifdef HAVE_CONFIGFILE
input_remapping_set_defaults(false); input_remapping_set_defaults(false);
@ -3775,10 +3718,6 @@ bool config_load_remap(const char *directory_input_remapping,
new_conf = NULL; new_conf = NULL;
free(content_path);
free(remap_directory);
free(core_path);
free(game_path);
return false; return false;
success: success:
@ -3786,11 +3725,6 @@ success:
runloop_msg_queue_push( runloop_msg_queue_push(
msg_hash_to_str(msg_remap_loaded), 1, 100, false, msg_hash_to_str(msg_remap_loaded), 1, 100, false,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
free(content_path);
free(remap_directory);
free(core_path);
free(game_path);
return true; return true;
} }
@ -3846,7 +3780,8 @@ static void video_driver_save_settings(config_file_t *conf)
* @user : Controller number to save * @user : Controller number to save
* Writes a controller autoconf file to disk. * Writes a controller autoconf file to disk.
**/ **/
bool config_save_autoconf_profile(const char *device_name, unsigned user) bool config_save_autoconf_profile(const
char *device_name, unsigned user)
{ {
static const char* invalid_filename_chars[] = { static const char* invalid_filename_chars[] = {
/* https://support.microsoft.com/en-us/help/905231/information-about-the-characters-that-you-cannot-use-in-site-names--fo */ /* https://support.microsoft.com/en-us/help/905231/information-about-the-characters-that-you-cannot-use-in-site-names--fo */
@ -3854,8 +3789,9 @@ bool config_save_autoconf_profile(const char *device_name, unsigned user)
NULL NULL
}; };
size_t i; size_t i;
char buf[PATH_MAX_LENGTH];
char autoconf_file[PATH_MAX_LENGTH];
config_file_t *conf = NULL; config_file_t *conf = NULL;
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
int32_t pid_user = 0; int32_t pid_user = 0;
int32_t vid_user = 0; int32_t vid_user = 0;
bool ret = false; bool ret = false;
@ -3864,16 +3800,9 @@ bool config_save_autoconf_profile(const char *device_name, unsigned user)
const char *joypad_driver_fallback = settings->arrays.input_joypad_driver; const char *joypad_driver_fallback = settings->arrays.input_joypad_driver;
const char *joypad_driver = NULL; const char *joypad_driver = NULL;
char *sanitised_name = NULL; char *sanitised_name = NULL;
char *buf = (char*)
malloc(PATH_MAX_LENGTH * sizeof(char));
char *autoconf_file = (char*)
malloc(PATH_MAX_LENGTH * sizeof(char));
if (!buf || !autoconf_file) buf[0] = '\0';
goto end; autoconf_file[0] = '\0';
buf[0] = '\0';
autoconf_file[0] = '\0';
if (string_is_empty(device_name)) if (string_is_empty(device_name))
goto end; goto end;
@ -3892,18 +3821,16 @@ bool config_save_autoconf_profile(const char *device_name, unsigned user)
goto end; goto end;
} }
/* Remove invalid filename characters from
* input device name */
sanitised_name = strdup(device_name); sanitised_name = strdup(device_name);
if (string_is_empty(sanitised_name)) /* Remove invalid filename characters from
goto end; * input device name */
for (i = 0; invalid_filename_chars[i]; i++) for (i = 0; invalid_filename_chars[i]; i++)
{ {
for (;;) for (;;)
{ {
char *tmp = strstr(sanitised_name, invalid_filename_chars[i]); char *tmp = strstr(sanitised_name,
invalid_filename_chars[i]);
if (tmp) if (tmp)
*tmp = '_'; *tmp = '_';
@ -3912,31 +3839,26 @@ bool config_save_autoconf_profile(const char *device_name, unsigned user)
} }
} }
/* Generate autconfig file path */ /* Generate autoconfig file path */
fill_pathname_join(buf, autoconf_dir, joypad_driver, path_size); fill_pathname_join(buf, autoconf_dir, joypad_driver, sizeof(buf));
if (path_is_directory(buf)) if (path_is_directory(buf))
{ {
char *buf_new = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char buf_new[PATH_MAX_LENGTH];
if (!buf_new)
goto end;
buf_new[0] = '\0'; buf_new[0] = '\0';
fill_pathname_join(buf_new, buf, fill_pathname_join(buf_new, buf,
sanitised_name, path_size); sanitised_name, sizeof(buf_new));
fill_pathname_noext(autoconf_file, fill_pathname_noext(autoconf_file,
buf_new, ".cfg", path_size); buf_new, ".cfg", sizeof(autoconf_file));
free(buf_new);
} }
else else
{ {
fill_pathname_join(buf, autoconf_dir, fill_pathname_join(buf, autoconf_dir,
sanitised_name, path_size); sanitised_name, sizeof(buf));
fill_pathname_noext(autoconf_file, fill_pathname_noext(autoconf_file,
buf, ".cfg", path_size); buf, ".cfg", sizeof(autoconf_file));
} }
/* Open config file */ /* Open config file */
@ -3982,12 +3904,6 @@ end:
if (sanitised_name) if (sanitised_name)
free(sanitised_name); free(sanitised_name);
if (buf)
free(buf);
if (autoconf_file)
free(autoconf_file);
if (conf) if (conf)
config_file_free(conf); config_file_free(conf);
@ -4225,7 +4141,6 @@ bool config_save_file(const char *path)
**/ **/
bool config_save_overrides(enum override_type type, void *data) bool config_save_overrides(enum override_type type, void *data)
{ {
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
int tmp_i = 0; int tmp_i = 0;
unsigned i = 0; unsigned i = 0;
bool ret = false; bool ret = false;
@ -4245,11 +4160,11 @@ bool config_save_overrides(enum override_type type, void *data)
struct config_array_setting *array_overrides= NULL; struct config_array_setting *array_overrides= NULL;
struct config_path_setting *path_settings = NULL; struct config_path_setting *path_settings = NULL;
struct config_path_setting *path_overrides = NULL; struct config_path_setting *path_overrides = NULL;
char *config_directory = NULL; char config_directory[PATH_MAX_LENGTH];
char *override_directory = NULL; char override_directory[PATH_MAX_LENGTH];
char *core_path = NULL; char core_path[PATH_MAX_LENGTH];
char *game_path = NULL; char game_path[PATH_MAX_LENGTH];
char *content_path = NULL; char content_path[PATH_MAX_LENGTH];
settings_t *overrides = config_get_ptr(); settings_t *overrides = config_get_ptr();
int bool_settings_size = sizeof(settings->bools) / sizeof(settings->bools.placeholder); int bool_settings_size = sizeof(settings->bools) / sizeof(settings->bools.placeholder);
int float_settings_size = sizeof(settings->floats) / sizeof(settings->floats.placeholder); int float_settings_size = sizeof(settings->floats) / sizeof(settings->floats.placeholder);
@ -4270,20 +4185,16 @@ bool config_save_overrides(enum override_type type, void *data)
if (string_is_empty(core_name) || string_is_empty(game_name)) if (string_is_empty(core_name) || string_is_empty(game_name))
return false; return false;
settings = (settings_t*)calloc(1, sizeof(settings_t)); settings = (settings_t*)calloc(1, sizeof(settings_t));
config_directory = (char*)malloc(PATH_MAX_LENGTH);
override_directory = (char*)malloc(PATH_MAX_LENGTH);
core_path = (char*)malloc(PATH_MAX_LENGTH);
game_path = (char*)malloc(PATH_MAX_LENGTH);
content_path = (char*)malloc(PATH_MAX_LENGTH);
config_directory[0] = override_directory[0] = core_path[0] = game_path[0] = '\0'; config_directory[0] = override_directory[0] = core_path[0] =
game_path[0] = '\0';
fill_pathname_application_special(config_directory, path_size, fill_pathname_application_special(config_directory, sizeof(config_directory),
APPLICATION_SPECIAL_DIRECTORY_CONFIG); APPLICATION_SPECIAL_DIRECTORY_CONFIG);
fill_pathname_join(override_directory, config_directory, core_name, fill_pathname_join(override_directory, config_directory, core_name,
path_size); sizeof(override_directory));
if (!path_is_directory(override_directory)) if (!path_is_directory(override_directory))
path_mkdir(override_directory); path_mkdir(override_directory);
@ -4293,19 +4204,19 @@ bool config_save_overrides(enum override_type type, void *data)
config_directory, core_name, config_directory, core_name,
game_name, game_name,
".cfg", ".cfg",
path_size); sizeof(game_path));
fill_pathname_join_special_ext(content_path, fill_pathname_join_special_ext(content_path,
config_directory, core_name, config_directory, core_name,
content_dir_name, content_dir_name,
".cfg", ".cfg",
path_size); sizeof(content_path));
fill_pathname_join_special_ext(core_path, fill_pathname_join_special_ext(core_path,
config_directory, core_name, config_directory, core_name,
core_name, core_name,
".cfg", ".cfg",
path_size); sizeof(core_path));
if (!conf) if (!conf)
conf = config_file_new_alloc(); conf = config_file_new_alloc();
@ -4464,11 +4375,6 @@ bool config_save_overrides(enum override_type type, void *data)
if (size_overrides) if (size_overrides)
free(size_overrides); free(size_overrides);
free(settings); free(settings);
free(config_directory);
free(override_directory);
free(core_path);
free(game_path);
free(content_path);
return ret; return ret;
} }
@ -4621,9 +4527,8 @@ bool input_remapping_save_file(const char *path)
{ {
bool ret; bool ret;
unsigned i, j, k; unsigned i, j, k;
size_t path_size = PATH_MAX_LENGTH * sizeof(char); char buf[PATH_MAX_LENGTH];
char *buf = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char remap_file[PATH_MAX_LENGTH];
char *remap_file = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
config_file_t *conf = NULL; config_file_t *conf = NULL;
unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS)); unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS));
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
@ -4631,18 +4536,13 @@ bool input_remapping_save_file(const char *path)
buf[0] = remap_file[0] = '\0'; buf[0] = remap_file[0] = '\0';
fill_pathname_join(buf, dir_input_remapping, path, path_size); fill_pathname_join(buf, dir_input_remapping, path, sizeof(buf));
fill_pathname_noext(remap_file, buf, ".rmp", path_size); fill_pathname_noext(remap_file, buf, ".rmp", sizeof(remap_file));
free(buf);
if (!(conf = config_file_new_from_path_to_string(remap_file))) if (!(conf = config_file_new_from_path_to_string(remap_file)))
{ {
if (!(conf = config_file_new_alloc())) if (!(conf = config_file_new_alloc()))
{
free(remap_file);
return false; return false;
}
} }
for (i = 0; i < max_users; i++) for (i = 0; i < max_users; i++)
@ -4715,26 +4615,20 @@ bool input_remapping_save_file(const char *path)
ret = config_file_write(conf, remap_file, true); ret = config_file_write(conf, remap_file, true);
config_file_free(conf); config_file_free(conf);
free(remap_file);
return ret; return ret;
} }
bool input_remapping_remove_file(const char *path, bool input_remapping_remove_file(const char *path,
const char *dir_input_remapping) const char *dir_input_remapping)
{ {
bool ret = false; char buf[PATH_MAX_LENGTH];
size_t path_size = PATH_MAX_LENGTH * sizeof(char); char remap_file[PATH_MAX_LENGTH];
char *buf = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
char *remap_file = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
buf[0] = remap_file[0] = '\0'; buf[0] = remap_file[0] = '\0';
fill_pathname_join(buf, dir_input_remapping, path, path_size); fill_pathname_join(buf, dir_input_remapping, path, sizeof(buf));
fill_pathname_noext(remap_file, buf, ".rmp", path_size); fill_pathname_noext(remap_file, buf, ".rmp", sizeof(remap_file));
ret = filestream_delete(remap_file) == 0 ? true : false; return filestream_delete(remap_file) == 0 ? true : false;
free(buf);
free(remap_file);
return ret;
} }
void input_remapping_set_defaults(bool deinit) void input_remapping_set_defaults(bool deinit)

View File

@ -195,21 +195,18 @@ static config_file_t *core_info_list_iterate(
const char *current_path, const char *current_path,
const char *path_basedir) const char *path_basedir)
{ {
size_t info_path_base_size = PATH_MAX_LENGTH * sizeof(char); char info_path[PATH_MAX_LENGTH];
char *info_path_base = NULL; char info_path_base[PATH_MAX_LENGTH];
char *info_path = NULL;
config_file_t *conf = NULL;
if (!current_path) if (!current_path)
return NULL; return NULL;
info_path_base = (char*)malloc(info_path_base_size); info_path [0] = '\0';
info_path_base[0] = '\0';
info_path_base[0] = '\0';
fill_pathname_base_noext(info_path_base, fill_pathname_base_noext(info_path_base,
current_path, current_path,
info_path_base_size); sizeof(info_path_base));
#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP) && !defined(_3DS) && !defined(VITA) && !defined(HW_WUP)) #if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP) && !defined(_3DS) && !defined(VITA) && !defined(HW_WUP))
{ {
@ -219,20 +216,15 @@ static config_file_t *core_info_list_iterate(
} }
#endif #endif
strlcat(info_path_base, ".info", info_path_base_size); strlcat(info_path_base, ".info", sizeof(info_path_base));
info_path = (char*)malloc(info_path_base_size);
fill_pathname_join(info_path, fill_pathname_join(info_path,
path_basedir, path_basedir,
info_path_base, info_path_base_size); info_path_base, sizeof(info_path_base));
free(info_path_base);
info_path_base = NULL;
if (path_is_valid(info_path)) if (path_is_valid(info_path))
conf = config_file_new_from_path_to_string(info_path); return config_file_new_from_path_to_string(info_path);
free(info_path); return NULL;
return conf;
} }
/* Returned path must be free()'d */ /* Returned path must be free()'d */
@ -633,9 +625,8 @@ static bool core_info_list_update_missing_firmware_internal(
bool *set_missing_bios) bool *set_missing_bios)
{ {
size_t i; size_t i;
char path[PATH_MAX_LENGTH];
core_info_t *info = NULL; core_info_t *info = NULL;
char *path = NULL;
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
if (!core_info_list || !core) if (!core_info_list || !core)
return false; return false;
@ -645,11 +636,6 @@ static bool core_info_list_update_missing_firmware_internal(
if (!info) if (!info)
return false; return false;
path = (char*)malloc(path_size);
if (!path)
return false;
path[0] = '\0'; path[0] = '\0';
for (i = 0; i < info->firmware_count; i++) for (i = 0; i < info->firmware_count; i++)
@ -658,13 +644,12 @@ static bool core_info_list_update_missing_firmware_internal(
continue; continue;
fill_pathname_join(path, systemdir, fill_pathname_join(path, systemdir,
info->firmware[i].path, path_size); info->firmware[i].path, sizeof(path));
info->firmware[i].missing = !path_is_valid(path); info->firmware[i].missing = !path_is_valid(path);
if (info->firmware[i].missing && !info->firmware[i].optional) if (info->firmware[i].missing && !info->firmware[i].optional)
*set_missing_bios = true; *set_missing_bios = true;
} }
free(path);
return true; return true;
} }
@ -1142,7 +1127,7 @@ core_updater_info_t *core_info_get_core_updater_info(const char *path)
return NULL; return NULL;
/* Create info struct */ /* Create info struct */
info = (core_updater_info_t*)malloc(sizeof(*info)); info = (core_updater_info_t*)malloc(sizeof(*info));
if (!info) if (!info)
return NULL; return NULL;

View File

@ -169,36 +169,24 @@ void fill_pathname_application_special(char *s,
case APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG: case APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG:
{ {
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
char *s1 = (char*)malloc(
PATH_MAX_LENGTH * sizeof(char));
const char *dir_assets = settings->paths.directory_assets; const char *dir_assets = settings->paths.directory_assets;
s1[0] = '\0'; fill_pathname_join(s, dir_assets, "pkg", len);
fill_pathname_join(s1, dir_assets, "pkg", PATH_MAX_LENGTH * sizeof(char));
strlcpy(s, s1, len);
free(s1);
} }
break; break;
case APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_ICONS: case APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_ICONS:
#ifdef HAVE_XMB #ifdef HAVE_XMB
{ {
char *s1 = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char s1[PATH_MAX_LENGTH];
char *s2 = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char s2[PATH_MAX_LENGTH];
s1[0] = '\0'; s1[0] = '\0';
s2[0] = '\0'; s2[0] = '\0';
fill_pathname_application_special(s1, fill_pathname_application_special(s1, sizeof(s1),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB); APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB);
fill_pathname_join(s2, s1, "png", fill_pathname_join(s2, s1, "png", sizeof(s2));
PATH_MAX_LENGTH * sizeof(char) fill_pathname_slash(s2, sizeof(s2));
);
fill_pathname_slash(s2,
PATH_MAX_LENGTH * sizeof(char)
);
strlcpy(s, s2, len); strlcpy(s, s2, len);
free(s1);
free(s2);
} }
#endif #endif
break; break;
@ -212,15 +200,13 @@ void fill_pathname_application_special(char *s,
strlcpy(s, path_menu_wallpaper, len); strlcpy(s, path_menu_wallpaper, len);
else else
{ {
char *s1 = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char s1[PATH_MAX_LENGTH];
s1[0] = '\0'; s1[0] = '\0';
fill_pathname_application_special(s1, fill_pathname_application_special(s1, sizeof(s1),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_ICONS); APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_ICONS);
fill_pathname_join(s, s1, "bg.png", len); fill_pathname_join(s, s1, "bg.png", len);
free(s1);
} }
} }
#endif #endif
@ -296,18 +282,10 @@ void fill_pathname_application_special(char *s,
case APPLICATION_SPECIAL_DIRECTORY_ASSETS_OZONE: case APPLICATION_SPECIAL_DIRECTORY_ASSETS_OZONE:
#ifdef HAVE_OZONE #ifdef HAVE_OZONE
{ {
char *s1 = (char*)malloc(
PATH_MAX_LENGTH * sizeof(char));
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
const char *dir_assets = settings->paths.directory_assets; const char *dir_assets = settings->paths.directory_assets;
fill_pathname_join(s, dir_assets, "ozone",
s1[0] = '\0'; len);
fill_pathname_join(s1, dir_assets, "ozone",
PATH_MAX_LENGTH * sizeof(char)
);
strlcpy(s, s1, len);
free(s1);
} }
#endif #endif
break; break;
@ -338,19 +316,15 @@ void fill_pathname_application_special(char *s,
case APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB: case APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB:
#ifdef HAVE_XMB #ifdef HAVE_XMB
{ {
char *s1 = (char*)malloc( char s1[PATH_MAX_LENGTH];
PATH_MAX_LENGTH * sizeof(char));
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
const char *dir_assets = settings->paths.directory_assets; const char *dir_assets = settings->paths.directory_assets;
s1[0] = '\0'; s1[0] = '\0';
fill_pathname_join(s1, dir_assets, "xmb", fill_pathname_join(s1, dir_assets, "xmb", sizeof(s1));
PATH_MAX_LENGTH * sizeof(char)
);
fill_pathname_join(s, fill_pathname_join(s,
s1, xmb_theme_ident(), len); s1, xmb_theme_ident(), len);
free(s1);
} }
#endif #endif
break; break;
@ -366,57 +340,40 @@ void fill_pathname_application_special(char *s,
break; break;
case APPLICATION_SPECIAL_DIRECTORY_ASSETS_MATERIALUI_ICONS: case APPLICATION_SPECIAL_DIRECTORY_ASSETS_MATERIALUI_ICONS:
#ifdef HAVE_MATERIALUI #ifdef HAVE_MATERIALUI
{ fill_pathname_application_special(s, len,
char *s1 = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); APPLICATION_SPECIAL_DIRECTORY_ASSETS_MATERIALUI);
s1[0] = '\0';
fill_pathname_application_special(s1,
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_MATERIALUI);
strlcpy(s, s1, len);
free(s1);
}
#endif #endif
break; break;
case APPLICATION_SPECIAL_DIRECTORY_ASSETS_MATERIALUI_FONT: case APPLICATION_SPECIAL_DIRECTORY_ASSETS_MATERIALUI_FONT:
#ifdef HAVE_MATERIALUI #ifdef HAVE_MATERIALUI
{ {
char *s1 = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char s1[PATH_MAX_LENGTH];
s1[0] = '\0'; s1[0] = '\0';
switch (*msg_hash_get_uint(MSG_HASH_USER_LANGUAGE)) switch (*msg_hash_get_uint(MSG_HASH_USER_LANGUAGE))
{ {
case RETRO_LANGUAGE_ARABIC: case RETRO_LANGUAGE_ARABIC:
case RETRO_LANGUAGE_PERSIAN: case RETRO_LANGUAGE_PERSIAN:
fill_pathname_application_special(s1, fill_pathname_application_special(s1, sizeof(s1),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG); APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG);
fill_pathname_join(s, s1, "fallback-font.ttf", len); fill_pathname_join(s, s1, "fallback-font.ttf", len);
break; break;
case RETRO_LANGUAGE_CHINESE_SIMPLIFIED: case RETRO_LANGUAGE_CHINESE_SIMPLIFIED:
case RETRO_LANGUAGE_CHINESE_TRADITIONAL: case RETRO_LANGUAGE_CHINESE_TRADITIONAL:
fill_pathname_application_special(s1, fill_pathname_application_special(s1, sizeof(s1),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG); APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG);
fill_pathname_join(s, s1, "chinese-fallback-font.ttf", len); fill_pathname_join(s, s1, "chinese-fallback-font.ttf", len);
break; break;
case RETRO_LANGUAGE_KOREAN: case RETRO_LANGUAGE_KOREAN:
fill_pathname_application_special(s1, fill_pathname_application_special(s1, sizeof(s1),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG); APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG);
fill_pathname_join(s, s1, "korean-fallback-font.ttf", len); fill_pathname_join(s, s1, "korean-fallback-font.ttf", len);
break; break;
default: default:
fill_pathname_application_special(s1, fill_pathname_application_special(s1, sizeof(s1),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_MATERIALUI); APPLICATION_SPECIAL_DIRECTORY_ASSETS_MATERIALUI);
fill_pathname_join(s, s1, "font.ttf", len); fill_pathname_join(s, s1, "font.ttf", len);
} }
free(s1);
} }
#endif #endif
break; break;
@ -430,90 +387,70 @@ void fill_pathname_application_special(char *s,
strlcpy(s, path_menu_xmb_font, len); strlcpy(s, path_menu_xmb_font, len);
else else
{ {
char *s1 = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char s1[PATH_MAX_LENGTH];
s1[0] = '\0'; s1[0] = '\0';
switch (*msg_hash_get_uint(MSG_HASH_USER_LANGUAGE)) switch (*msg_hash_get_uint(MSG_HASH_USER_LANGUAGE))
{ {
case RETRO_LANGUAGE_ARABIC: case RETRO_LANGUAGE_ARABIC:
case RETRO_LANGUAGE_PERSIAN: case RETRO_LANGUAGE_PERSIAN:
fill_pathname_application_special(s1, fill_pathname_application_special(s1, sizeof(s1),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG); APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG);
fill_pathname_join(s, s1, "fallback-font.ttf", len); fill_pathname_join(s, s1, "fallback-font.ttf", len);
break; break;
case RETRO_LANGUAGE_CHINESE_SIMPLIFIED: case RETRO_LANGUAGE_CHINESE_SIMPLIFIED:
case RETRO_LANGUAGE_CHINESE_TRADITIONAL: case RETRO_LANGUAGE_CHINESE_TRADITIONAL:
fill_pathname_application_special(s1, fill_pathname_application_special(s1, sizeof(s1),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG); APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG);
fill_pathname_join(s, s1, "chinese-fallback-font.ttf", len); fill_pathname_join(s, s1, "chinese-fallback-font.ttf", len);
break; break;
case RETRO_LANGUAGE_KOREAN: case RETRO_LANGUAGE_KOREAN:
fill_pathname_application_special(s1, fill_pathname_application_special(s1, sizeof(s1),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG); APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG);
fill_pathname_join(s, s1, "korean-fallback-font.ttf", len); fill_pathname_join(s, s1, "korean-fallback-font.ttf", len);
break; break;
default: default:
fill_pathname_application_special(s1, fill_pathname_application_special(s1, sizeof(s1),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB); APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB);
fill_pathname_join(s, s1, "font.ttf", len); fill_pathname_join(s, s1, "font.ttf", len);
} }
free(s1);
} }
} }
#endif #endif
break; break;
case APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_DISCORD_AVATARS: case APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_DISCORD_AVATARS:
{ {
char *s1 = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char s1[PATH_MAX_LENGTH];
char *s2 = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char s2[PATH_MAX_LENGTH];
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
const char *dir_thumbnails = settings->paths.directory_thumbnails; const char *dir_thumbnails = settings->paths.directory_thumbnails;
s1[0] = '\0'; s1[0] = '\0';
s2[0] = '\0'; s2[0] = '\0';
fill_pathname_join(s1, dir_thumbnails, "discord", len); fill_pathname_join(s1, dir_thumbnails, "discord", sizeof(s1));
fill_pathname_join(s2, fill_pathname_join(s2,
s1, "avatars", s1, "avatars", sizeof(s2));
PATH_MAX_LENGTH * sizeof(char) fill_pathname_slash(s2, sizeof(s2));
);
fill_pathname_slash(s2,
PATH_MAX_LENGTH * sizeof(char)
);
strlcpy(s, s2, len); strlcpy(s, s2, len);
free(s1);
free(s2);
} }
break; break;
case APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_CHEEVOS_BADGES: case APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_CHEEVOS_BADGES:
{ {
char *s1 = (char*)malloc( char s1[PATH_MAX_LENGTH];
PATH_MAX_LENGTH * sizeof(char)); char s2[PATH_MAX_LENGTH];
char *s2 = (char*)malloc(
PATH_MAX_LENGTH * sizeof(char));
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
const char *dir_thumbnails = settings->paths.directory_thumbnails; const char *dir_thumbnails = settings->paths.directory_thumbnails;
s1[0] = '\0'; s1[0] = '\0';
s2[0] = '\0'; s2[0] = '\0';
fill_pathname_join(s1, dir_thumbnails, "cheevos", len); fill_pathname_join(s1, dir_thumbnails, "cheevos", len);
fill_pathname_join(s2, fill_pathname_join(s2,
s1, "badges", s1, "badges", sizeof(s2));
PATH_MAX_LENGTH * sizeof(char) fill_pathname_slash(s2, sizeof(s2));
);
fill_pathname_slash(s2,
PATH_MAX_LENGTH * sizeof(char)
);
strlcpy(s, s2, len); strlcpy(s, s2, len);
free(s1);
free(s2);
} }
break; break;

View File

@ -417,7 +417,7 @@ end:
static int general_push(menu_displaylist_info_t *info, static int general_push(menu_displaylist_info_t *info,
unsigned id, enum menu_displaylist_ctl_state state) unsigned id, enum menu_displaylist_ctl_state state)
{ {
char *newstring2 = NULL; char newstring2[PATH_MAX_LENGTH];
core_info_list_t *list = NULL; core_info_list_t *list = NULL;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
menu_handle_t *menu = menu_driver_get_ptr(); menu_handle_t *menu = menu_driver_get_ptr();
@ -473,8 +473,6 @@ static int general_push(menu_displaylist_info_t *info,
break; break;
} }
newstring2 = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
newstring2[0] = '\0'; newstring2[0] = '\0';
switch (id) switch (id)
@ -484,11 +482,9 @@ static int general_push(menu_displaylist_info_t *info,
struct retro_system_info *system = struct retro_system_info *system =
runloop_get_libretro_system_info(); runloop_get_libretro_system_info();
if (system) if (system)
{
if (!string_is_empty(system->valid_extensions)) if (!string_is_empty(system->valid_extensions))
strlcpy(newstring2, system->valid_extensions, strlcpy(newstring2, system->valid_extensions,
PATH_MAX_LENGTH * sizeof(char)); sizeof(newstring2));
}
} }
break; break;
case PUSH_DEFAULT: case PUSH_DEFAULT:
@ -496,9 +492,8 @@ static int general_push(menu_displaylist_info_t *info,
bool new_exts_allocated = false; bool new_exts_allocated = false;
char *new_exts = NULL; char *new_exts = NULL;
if (menu_setting_get_browser_selection_type(info->setting) == ST_DIR) if (menu_setting_get_browser_selection_type(info->setting)
{ == ST_DIR) { }
}
else else
{ {
struct retro_system_info *system = struct retro_system_info *system =
@ -515,19 +510,15 @@ static int general_push(menu_displaylist_info_t *info,
if (!string_is_empty(new_exts)) if (!string_is_empty(new_exts))
{ {
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
struct string_list *str_list3 = string_split(new_exts, "|"); struct string_list *str_list3 = string_split(new_exts, "|");
#ifdef HAVE_IBXM #ifdef HAVE_IBXM
{ union string_list_elem_attr attr;
union string_list_elem_attr attr; attr.i = 0;
attr.i = 0; string_list_append(str_list3, "s3m", attr);
string_list_append(str_list3, "s3m", attr); string_list_append(str_list3, "mod", attr);
string_list_append(str_list3, "mod", attr); string_list_append(str_list3, "xm", attr);
string_list_append(str_list3, "xm", attr);
}
#endif #endif
string_list_join_concat(newstring2, path_size, string_list_join_concat(newstring2, sizeof(newstring2),
str_list3, "|"); str_list3, "|");
string_list_free(str_list3); string_list_free(str_list3);
@ -546,8 +537,7 @@ static int general_push(menu_displaylist_info_t *info,
case PUSH_DETECT_CORE_LIST: case PUSH_DETECT_CORE_LIST:
{ {
union string_list_elem_attr attr; union string_list_elem_attr attr;
size_t path_size = PATH_MAX_LENGTH * sizeof(char); char newstring[PATH_MAX_LENGTH];
char *newstring = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
struct string_list *str_list2 = string_list_new(); struct string_list *str_list2 = string_list_new();
struct retro_system_info *system = runloop_get_libretro_system_info(); struct retro_system_info *system = runloop_get_libretro_system_info();
@ -593,7 +583,7 @@ static int general_push(menu_displaylist_info_t *info,
} }
} }
string_list_join_concat(newstring, path_size, string_list_join_concat(newstring, sizeof(newstring),
str_list2, "|"); str_list2, "|");
{ {
@ -608,11 +598,10 @@ static int general_push(menu_displaylist_info_t *info,
string_list_append(str_list3, "xm", attr); string_list_append(str_list3, "xm", attr);
} }
#endif #endif
string_list_join_concat(newstring2, path_size, string_list_join_concat(newstring2, sizeof(newstring2),
str_list3, "|"); str_list3, "|");
string_list_free(str_list3); string_list_free(str_list3);
} }
free(newstring);
string_list_free(str_list2); string_list_free(str_list2);
} }
break; break;
@ -632,18 +621,17 @@ static int general_push(menu_displaylist_info_t *info,
#elif defined(HAVE_MPV) #elif defined(HAVE_MPV)
libretro_mpv_retro_get_system_info(&sysinfo); libretro_mpv_retro_get_system_info(&sysinfo);
#endif #endif
strlcat(newstring2, "|", PATH_MAX_LENGTH * sizeof(char)); strlcat(newstring2, "|", sizeof(newstring2));
strlcat(newstring2, sysinfo.valid_extensions, strlcat(newstring2, sysinfo.valid_extensions, sizeof(newstring2));
PATH_MAX_LENGTH * sizeof(char));
} }
#endif #endif
#ifdef HAVE_IMAGEVIEWER #ifdef HAVE_IMAGEVIEWER
if (multimedia_builtin_imageviewer_enable) if (multimedia_builtin_imageviewer_enable)
{ {
libretro_imageviewer_retro_get_system_info(&sysinfo); libretro_imageviewer_retro_get_system_info(&sysinfo);
strlcat(newstring2, "|", PATH_MAX_LENGTH * sizeof(char)); strlcat(newstring2, "|", sizeof(newstring2));
strlcat(newstring2, sysinfo.valid_extensions, strlcat(newstring2, sysinfo.valid_extensions,
PATH_MAX_LENGTH * sizeof(char)); sizeof(newstring2));
} }
#endif #endif
} }
@ -654,7 +642,6 @@ static int general_push(menu_displaylist_info_t *info,
free(info->exts); free(info->exts);
info->exts = strdup(newstring2); info->exts = strdup(newstring2);
} }
free(newstring2);
return deferred_push_dlist(info, state); return deferred_push_dlist(info, state);
} }

View File

@ -1467,35 +1467,34 @@ static int file_load_with_detect_core_wrapper(
const char *path, const char *label, const char *path, const char *label,
unsigned type, bool is_carchive) unsigned type, bool is_carchive)
{ {
menu_content_ctx_defer_info_t def_info;
int ret = 0; int ret = 0;
char *new_core_path = NULL;
const char *menu_path = NULL;
const char *menu_label = NULL;
core_info_list_t *list = NULL;
menu_handle_t *menu = menu_driver_get_ptr(); menu_handle_t *menu = menu_driver_get_ptr();
if (!menu) if (!menu)
return menu_cbs_exit(); return menu_cbs_exit();
{ {
char *menu_path_new = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); menu_content_ctx_defer_info_t def_info;
new_core_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char menu_path_new[PATH_MAX_LENGTH];
char new_core_path[PATH_MAX_LENGTH];
const char *menu_path = NULL;
const char *menu_label = NULL;
core_info_list_t *list = NULL;
new_core_path[0] = menu_path_new[0] = '\0'; new_core_path[0] = menu_path_new[0] = '\0';
menu_entries_get_last_stack(&menu_path, &menu_label, NULL, NULL, NULL); menu_entries_get_last_stack(&menu_path, &menu_label, NULL, NULL, NULL);
if (!string_is_empty(menu_path)) if (!string_is_empty(menu_path))
strlcpy(menu_path_new, menu_path, PATH_MAX_LENGTH * sizeof(char)); strlcpy(menu_path_new, menu_path, sizeof(menu_path_new));
if (string_is_equal(menu_label, if (string_is_equal(menu_label,
msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_ARCHIVE_OPEN_DETECT_CORE))) msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_ARCHIVE_OPEN_DETECT_CORE)))
fill_pathname_join(menu_path_new, menu->scratch2_buf, menu->scratch_buf, fill_pathname_join(menu_path_new,
PATH_MAX_LENGTH * sizeof(char)); menu->scratch2_buf, menu->scratch_buf, sizeof(menu_path_new));
else if (string_is_equal(menu_label, else if (string_is_equal(menu_label,
msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_ARCHIVE_OPEN))) msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_ARCHIVE_OPEN)))
fill_pathname_join(menu_path_new, menu->scratch2_buf, menu->scratch_buf, fill_pathname_join(menu_path_new,
PATH_MAX_LENGTH * sizeof(char)); menu->scratch2_buf, menu->scratch_buf, sizeof(menu_path_new));
core_info_get_list(&list); core_info_get_list(&list);
@ -1507,7 +1506,7 @@ static int file_load_with_detect_core_wrapper(
def_info.len = sizeof(menu->deferred_path); def_info.len = sizeof(menu->deferred_path);
if (menu_content_find_first_core(&def_info, false, new_core_path, if (menu_content_find_first_core(&def_info, false, new_core_path,
PATH_MAX_LENGTH * sizeof(char))) sizeof(new_core_path)))
ret = -1; ret = -1;
if ( !is_carchive && !string_is_empty(path) if ( !is_carchive && !string_is_empty(path)
@ -1516,14 +1515,9 @@ static int file_load_with_detect_core_wrapper(
menu_path_new, path, menu_path_new, path,
sizeof(menu->detect_content_path)); sizeof(menu->detect_content_path));
free(menu_path_new);
if (enum_label_idx == MENU_ENUM_LABEL_COLLECTION) if (enum_label_idx == MENU_ENUM_LABEL_COLLECTION)
{
free(new_core_path);
return generic_action_ok_displaylist_push(path, NULL, return generic_action_ok_displaylist_push(path, NULL,
NULL, 0, idx, entry_idx, ACTION_OK_DL_DEFERRED_CORE_LIST_SET); NULL, 0, idx, entry_idx, ACTION_OK_DL_DEFERRED_CORE_LIST_SET);
}
switch (ret) switch (ret)
{ {
@ -1541,10 +1535,8 @@ static int file_load_with_detect_core_wrapper(
&content_info, &content_info,
CORE_TYPE_PLAIN, CORE_TYPE_PLAIN,
NULL, NULL)) NULL, NULL))
{
free(new_core_path);
return -1; return -1;
}
content_add_to_playlist(def_info.s); content_add_to_playlist(def_info.s);
ret = 0; ret = 0;
@ -1559,7 +1551,6 @@ static int file_load_with_detect_core_wrapper(
} }
} }
free(new_core_path);
return ret; return ret;
} }
@ -2562,7 +2553,7 @@ static int action_ok_audio_add_to_mixer_and_collection(const char *path,
struct playlist_entry entry = {0}; struct playlist_entry entry = {0};
menu_handle_t *menu = menu_driver_get_ptr(); menu_handle_t *menu = menu_driver_get_ptr();
combined_path[0] = '\0'; combined_path[0] = '\0';
if (!menu) if (!menu)
return menu_cbs_exit(); return menu_cbs_exit();
@ -2593,7 +2584,7 @@ static int action_ok_audio_add_to_mixer_and_collection_and_play(const char *path
struct playlist_entry entry = {0}; struct playlist_entry entry = {0};
menu_handle_t *menu = menu_driver_get_ptr(); menu_handle_t *menu = menu_driver_get_ptr();
combined_path[0] = '\0'; combined_path[0] = '\0';
if (!menu) if (!menu)
return menu_cbs_exit(); return menu_cbs_exit();
@ -3214,12 +3205,12 @@ static int action_ok_path_scan_directory(const char *path,
static int action_ok_path_manual_scan_directory(const char *path, static int action_ok_path_manual_scan_directory(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx) const char *label, unsigned type, size_t idx, size_t entry_idx)
{ {
char content_dir[PATH_MAX_LENGTH];
const char *flush_char = msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_MANUAL_CONTENT_SCAN_LIST); const char *flush_char = msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_MANUAL_CONTENT_SCAN_LIST);
unsigned flush_type = 0; unsigned flush_type = 0;
const char *menu_path = NULL; const char *menu_path = NULL;
char content_dir[PATH_MAX_LENGTH];
content_dir[0] = '\0'; content_dir[0] = '\0';
/* 'Reset' file browser */ /* 'Reset' file browser */
filebrowser_clear_type(); filebrowser_clear_type();
@ -6054,12 +6045,12 @@ static int action_ok_load_archive(const char *path,
static int action_ok_load_archive_detect_core(const char *path, static int action_ok_load_archive_detect_core(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx) const char *label, unsigned type, size_t idx, size_t entry_idx)
{ {
char new_core_path[PATH_MAX_LENGTH];
menu_content_ctx_defer_info_t def_info; menu_content_ctx_defer_info_t def_info;
int ret = 0; int ret = 0;
core_info_list_t *list = NULL; core_info_list_t *list = NULL;
const char *menu_path = NULL; const char *menu_path = NULL;
const char *content_path = NULL; const char *content_path = NULL;
char *new_core_path = NULL;
menu_handle_t *menu = menu_driver_get_ptr(); menu_handle_t *menu = menu_driver_get_ptr();
if (!menu) if (!menu)
@ -6077,12 +6068,10 @@ static int action_ok_load_archive_detect_core(const char *path,
def_info.s = menu->deferred_path; def_info.s = menu->deferred_path;
def_info.len = sizeof(menu->deferred_path); def_info.len = sizeof(menu->deferred_path);
new_core_path = (char*)
malloc(PATH_MAX_LENGTH * sizeof(char));
new_core_path[0] = '\0'; new_core_path[0] = '\0';
if (menu_content_find_first_core(&def_info, false, if (menu_content_find_first_core(&def_info, false,
new_core_path, PATH_MAX_LENGTH * sizeof(char))) new_core_path, sizeof(new_core_path)))
ret = -1; ret = -1;
fill_pathname_join(menu->detect_content_path, menu_path, content_path, fill_pathname_join(menu->detect_content_path, menu_path, content_path,
@ -6119,7 +6108,6 @@ static int action_ok_load_archive_detect_core(const char *path,
break; break;
} }
free(new_core_path);
return ret; return ret;
} }

View File

@ -972,12 +972,12 @@ static void ozone_cache_footer_labels(ozone_handle_t *ozone)
/* Determines the size of all menu elements */ /* Determines the size of all menu elements */
static void ozone_set_layout(ozone_handle_t *ozone, bool is_threaded) static void ozone_set_layout(ozone_handle_t *ozone, bool is_threaded)
{ {
char s1[PATH_MAX_LENGTH];
char font_path[PATH_MAX_LENGTH]; char font_path[PATH_MAX_LENGTH];
float scale_factor = 0.0f; float scale_factor = 0.0f;
bool font_inited = false; bool font_inited = false;
char *s1 = NULL;
font_path[0] = '\0'; font_path[0] = s1[0]= '\0';
if (!ozone) if (!ozone)
return; return;
@ -1033,27 +1033,22 @@ static void ozone_set_layout(ozone_handle_t *ozone, bool is_threaded)
ozone->pointer_active_delta = CURSOR_ACTIVE_DELTA * scale_factor; ozone->pointer_active_delta = CURSOR_ACTIVE_DELTA * scale_factor;
/* Initialise fonts */ /* Initialise fonts */
s1 = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
s1[0] = '\0';
switch (*msg_hash_get_uint(MSG_HASH_USER_LANGUAGE)) switch (*msg_hash_get_uint(MSG_HASH_USER_LANGUAGE))
{ {
case RETRO_LANGUAGE_ARABIC: case RETRO_LANGUAGE_ARABIC:
case RETRO_LANGUAGE_PERSIAN: case RETRO_LANGUAGE_PERSIAN:
fill_pathname_application_special(s1, fill_pathname_application_special(s1, sizeof(s1),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG); APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG);
fill_pathname_join(font_path, s1, "fallback-font.ttf", sizeof(font_path)); fill_pathname_join(font_path, s1, "fallback-font.ttf", sizeof(font_path));
break; break;
case RETRO_LANGUAGE_CHINESE_SIMPLIFIED: case RETRO_LANGUAGE_CHINESE_SIMPLIFIED:
case RETRO_LANGUAGE_CHINESE_TRADITIONAL: case RETRO_LANGUAGE_CHINESE_TRADITIONAL:
fill_pathname_application_special(s1, fill_pathname_application_special(s1, sizeof(s1),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG); APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG);
fill_pathname_join(font_path, s1, "chinese-fallback-font.ttf", sizeof(font_path)); fill_pathname_join(font_path, s1, "chinese-fallback-font.ttf", sizeof(font_path));
break; break;
case RETRO_LANGUAGE_KOREAN: case RETRO_LANGUAGE_KOREAN:
fill_pathname_application_special(s1, fill_pathname_application_special(s1, sizeof(s1),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG); APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG);
fill_pathname_join(font_path, s1, "korean-fallback-font.ttf", sizeof(font_path)); fill_pathname_join(font_path, s1, "korean-fallback-font.ttf", sizeof(font_path));
break; break;
@ -1069,21 +1064,18 @@ static void ozone_set_layout(ozone_handle_t *ozone, bool is_threaded)
{ {
case RETRO_LANGUAGE_ARABIC: case RETRO_LANGUAGE_ARABIC:
case RETRO_LANGUAGE_PERSIAN: case RETRO_LANGUAGE_PERSIAN:
fill_pathname_application_special(s1, fill_pathname_application_special(s1, sizeof(s1),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG); APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG);
fill_pathname_join(font_path, s1, "fallback-font.ttf", sizeof(font_path)); fill_pathname_join(font_path, s1, "fallback-font.ttf", sizeof(font_path));
break; break;
case RETRO_LANGUAGE_CHINESE_SIMPLIFIED: case RETRO_LANGUAGE_CHINESE_SIMPLIFIED:
case RETRO_LANGUAGE_CHINESE_TRADITIONAL: case RETRO_LANGUAGE_CHINESE_TRADITIONAL:
fill_pathname_application_special(s1, fill_pathname_application_special(s1, sizeof(s1),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG); APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG);
fill_pathname_join(font_path, s1, "chinese-fallback-font.ttf", sizeof(font_path)); fill_pathname_join(font_path, s1, "chinese-fallback-font.ttf", sizeof(font_path));
break; break;
case RETRO_LANGUAGE_KOREAN: case RETRO_LANGUAGE_KOREAN:
fill_pathname_application_special(s1, fill_pathname_application_special(s1, sizeof(s1),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG); APPLICATION_SPECIAL_DIRECTORY_ASSETS_PKG);
fill_pathname_join(font_path, s1, "korean-fallback-font.ttf", sizeof(font_path)); fill_pathname_join(font_path, s1, "korean-fallback-font.ttf", sizeof(font_path));
break; break;
@ -1091,8 +1083,6 @@ static void ozone_set_layout(ozone_handle_t *ozone, bool is_threaded)
fill_pathname_join(font_path, ozone->assets_path, "regular.ttf", sizeof(font_path)); fill_pathname_join(font_path, ozone->assets_path, "regular.ttf", sizeof(font_path));
} }
free(s1);
font_inited = ozone_init_font(&ozone->fonts.footer, font_inited = ozone_init_font(&ozone->fonts.footer,
is_threaded, font_path, FONT_SIZE_FOOTER * scale_factor); is_threaded, font_path, FONT_SIZE_FOOTER * scale_factor);
ozone->has_all_assets = ozone->has_all_assets && font_inited; ozone->has_all_assets = ozone->has_all_assets && font_inited;

View File

@ -884,32 +884,25 @@ void ozone_context_reset_horizontal_list(ozone_handle_t *ozone)
{ {
struct texture_image ti; struct texture_image ti;
char *sysname = (char*) char sysname[PATH_MAX_LENGTH];
malloc(PATH_MAX_LENGTH * sizeof(char)); char texturepath[PATH_MAX_LENGTH];
char *texturepath = (char*) char content_texturepath[PATH_MAX_LENGTH];
malloc(PATH_MAX_LENGTH * sizeof(char)); char icons_path[PATH_MAX_LENGTH];
char *content_texturepath = (char*)
malloc(PATH_MAX_LENGTH * sizeof(char));
char *icons_path = (char*)
malloc(PATH_MAX_LENGTH * sizeof(char));
strlcpy(icons_path, ozone->icons_path, PATH_MAX_LENGTH * sizeof(char)); strlcpy(icons_path, ozone->icons_path, sizeof(icons_path));
sysname[0] = texturepath[0] = content_texturepath[0] = '\0'; sysname[0] = texturepath[0] = content_texturepath[0] = '\0';
fill_pathname_base_noext(sysname, path, fill_pathname_base_noext(sysname, path, sizeof(sysname));
PATH_MAX_LENGTH * sizeof(char));
fill_pathname_join_concat(texturepath, icons_path, sysname, fill_pathname_join_concat(texturepath, icons_path, sysname,
".png", ".png", sizeof(texturepath));
PATH_MAX_LENGTH * sizeof(char));
/* If the playlist icon doesn't exist return default */ /* If the playlist icon doesn't exist return default */
if (!path_is_valid(texturepath)) if (!path_is_valid(texturepath))
fill_pathname_join_concat(texturepath, icons_path, "default", fill_pathname_join_concat(texturepath, icons_path, "default",
".png", ".png", sizeof(texturepath));
PATH_MAX_LENGTH * sizeof(char));
ti.width = 0; ti.width = 0;
ti.height = 0; ti.height = 0;
@ -929,22 +922,18 @@ void ozone_context_reset_horizontal_list(ozone_handle_t *ozone)
} }
fill_pathname_join_delim(sysname, sysname, fill_pathname_join_delim(sysname, sysname,
"content.png", '-', "content.png", '-', sizeof(sysname));
PATH_MAX_LENGTH * sizeof(char)); strlcat(content_texturepath, icons_path, sizeof(content_texturepath));
strlcat(content_texturepath, icons_path, strlcat(content_texturepath, PATH_DEFAULT_SLASH(), sizeof(content_texturepath));
PATH_MAX_LENGTH * sizeof(char)); strlcat(content_texturepath, sysname, sizeof(content_texturepath));
strlcat(content_texturepath, PATH_DEFAULT_SLASH(),
PATH_MAX_LENGTH * sizeof(char));
strlcat(content_texturepath, sysname, PATH_MAX_LENGTH * sizeof(char));
/* If the content icon doesn't exist return default-content */ /* If the content icon doesn't exist return default-content */
if (!path_is_valid(content_texturepath)) if (!path_is_valid(content_texturepath))
{ {
strlcat(icons_path, strlcat(icons_path,
PATH_DEFAULT_SLASH() "default", PATH_MAX_LENGTH * sizeof(char)); PATH_DEFAULT_SLASH() "default", sizeof(icons_path));
fill_pathname_join_delim(content_texturepath, icons_path, fill_pathname_join_delim(content_texturepath, icons_path,
"content.png", '-', "content.png", '-', sizeof(content_texturepath));
PATH_MAX_LENGTH * sizeof(char));
} }
if (image_texture_load(&ti, content_texturepath)) if (image_texture_load(&ti, content_texturepath))
@ -972,11 +961,6 @@ void ozone_context_reset_horizontal_list(ozone_handle_t *ozone)
* dereferencing in case of unknown errors... */ * dereferencing in case of unknown errors... */
node->console_name = strdup( node->console_name = strdup(
console_name ? console_name : path); console_name ? console_name : path);
free(sysname);
free(texturepath);
free(content_texturepath);
free(icons_path);
} }
} }
} }

View File

@ -1765,8 +1765,7 @@ static void xmb_list_switch_new(xmb_handle_t *xmb,
if (menu_dynamic_wallpaper_enable) if (menu_dynamic_wallpaper_enable)
{ {
size_t path_size = PATH_MAX_LENGTH * sizeof(char); char path[PATH_MAX_LENGTH];
char *path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
char *tmp = string_replace_substring(xmb->title_name, "/", " "); char *tmp = string_replace_substring(xmb->title_name, "/", " ");
path[0] = '\0'; path[0] = '\0';
@ -1777,14 +1776,14 @@ static void xmb_list_switch_new(xmb_handle_t *xmb,
path, path,
dir_dynamic_wallpapers, dir_dynamic_wallpapers,
tmp, tmp,
path_size); sizeof(path));
free(tmp); free(tmp);
} }
strlcat(path, ".png", path_size); strlcat(path, ".png", sizeof(path));
if (!path_is_valid(path)) if (!path_is_valid(path))
fill_pathname_application_special(path, path_size, fill_pathname_application_special(path, sizeof(path),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_BG); APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_BG);
if (!string_is_equal(path, xmb->bg_file_path)) if (!string_is_equal(path, xmb->bg_file_path))
@ -1799,8 +1798,6 @@ static void xmb_list_switch_new(xmb_handle_t *xmb,
xmb->bg_file_path = strdup(path); xmb->bg_file_path = strdup(path);
} }
} }
free(path);
} }
end = file_list_get_size(list); end = file_list_get_size(list);
@ -2163,41 +2160,30 @@ static void xmb_context_reset_horizontal_list(
if (!path) if (!path)
continue; continue;
if (!string_ends_with_size(path, ".lpl", if (string_ends_with_size(path, ".lpl",
strlen(path), STRLEN_CONST(".lpl"))) strlen(path), STRLEN_CONST(".lpl")))
continue;
{ {
struct texture_image ti; struct texture_image ti;
char *sysname = (char*) char sysname[PATH_MAX_LENGTH];
malloc(PATH_MAX_LENGTH * sizeof(char)); char iconpath[PATH_MAX_LENGTH];
char *iconpath = (char*) char texturepath[PATH_MAX_LENGTH];
malloc(PATH_MAX_LENGTH * sizeof(char)); char content_texturepath[PATH_MAX_LENGTH];
char *texturepath = (char*)
malloc(PATH_MAX_LENGTH * sizeof(char));
char *content_texturepath = (char*)
malloc(PATH_MAX_LENGTH * sizeof(char));
iconpath[0] = sysname[0] = iconpath[0] = sysname[0] =
texturepath[0] = content_texturepath[0] = '\0'; texturepath[0] = content_texturepath[0] = '\0';
fill_pathname_base_noext(sysname, path, fill_pathname_base_noext(sysname, path, sizeof(sysname));
PATH_MAX_LENGTH * sizeof(char)); fill_pathname_application_special(iconpath, sizeof(iconpath),
fill_pathname_application_special(iconpath,
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_ICONS); APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_ICONS);
fill_pathname_join_concat(texturepath, iconpath, sysname, fill_pathname_join_concat(texturepath, iconpath, sysname,
".png", ".png", sizeof(texturepath));
PATH_MAX_LENGTH * sizeof(char));
/* If the playlist icon doesn't exist return default */ /* If the playlist icon doesn't exist return default */
if (!path_is_valid(texturepath)) if (!path_is_valid(texturepath))
fill_pathname_join_concat(texturepath, iconpath, "default", fill_pathname_join_concat(texturepath, iconpath, "default",
".png", ".png", sizeof(texturepath));
PATH_MAX_LENGTH * sizeof(char));
ti.width = 0; ti.width = 0;
ti.height = 0; ti.height = 0;
@ -2216,10 +2202,10 @@ static void xmb_context_reset_horizontal_list(
image_texture_free(&ti); image_texture_free(&ti);
} }
fill_pathname_join_delim(sysname, sysname, "content.png", fill_pathname_join_delim(sysname, sysname, "content.png", '-',
'-', PATH_MAX_LENGTH * sizeof(char)); sizeof(sysname));
strlcat(content_texturepath, iconpath, PATH_MAX_LENGTH * sizeof(char)); strlcat(content_texturepath, iconpath, sizeof(content_texturepath));
strlcat(content_texturepath, sysname, PATH_MAX_LENGTH * sizeof(char)); strlcat(content_texturepath, sysname, sizeof(content_texturepath));
/* If the content icon doesn't exist return default-content */ /* If the content icon doesn't exist return default-content */
@ -2242,11 +2228,6 @@ static void xmb_context_reset_horizontal_list(
image_texture_free(&ti); image_texture_free(&ti);
} }
free(sysname);
free(iconpath);
free(texturepath);
free(content_texturepath);
} }
} }
@ -6067,8 +6048,8 @@ static void xmb_context_reset_background(const char *iconpath)
static void xmb_context_reset_internal(xmb_handle_t *xmb, static void xmb_context_reset_internal(xmb_handle_t *xmb,
bool is_threaded, bool reinit_textures) bool is_threaded, bool reinit_textures)
{ {
char iconpath[PATH_MAX_LENGTH];
char bg_file_path[PATH_MAX_LENGTH] = {0}; char bg_file_path[PATH_MAX_LENGTH] = {0};
char *iconpath = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
iconpath[0] = '\0'; iconpath[0] = '\0';
fill_pathname_application_special(bg_file_path, fill_pathname_application_special(bg_file_path,
@ -6081,8 +6062,7 @@ static void xmb_context_reset_internal(xmb_handle_t *xmb,
xmb->bg_file_path = strdup(bg_file_path); xmb->bg_file_path = strdup(bg_file_path);
} }
fill_pathname_application_special(iconpath, fill_pathname_application_special(iconpath, sizeof(iconpath),
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_ICONS); APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_ICONS);
xmb_layout(xmb); xmb_layout(xmb);
@ -6131,8 +6111,6 @@ static void xmb_context_reset_internal(xmb_handle_t *xmb,
} }
xmb_update_savestate_thumbnail_image(xmb); xmb_update_savestate_thumbnail_image(xmb);
free(iconpath);
} }
static void xmb_context_reset(void *data, bool is_threaded) static void xmb_context_reset(void *data, bool is_threaded)

View File

@ -867,7 +867,7 @@ static void task_load_handler(retro_task_t *task)
{ {
if (state->autoload) if (state->autoload)
{ {
char *msg = (char*)malloc(8192 * sizeof(char)); char msg[8192];
msg[0] = '\0'; msg[0] = '\0';
@ -878,7 +878,6 @@ static void task_load_handler(retro_task_t *task)
state->path, state->path,
msg_hash_to_str(MSG_FAILED)); msg_hash_to_str(MSG_FAILED));
task_set_error(task, strdup(msg)); task_set_error(task, strdup(msg));
free(msg);
} }
else else
task_set_error(task, strdup(msg_hash_to_str(MSG_FAILED_TO_LOAD_STATE))); task_set_error(task, strdup(msg_hash_to_str(MSG_FAILED_TO_LOAD_STATE)));
@ -891,15 +890,14 @@ static void task_load_handler(retro_task_t *task)
if (state->bytes_read == state->size) if (state->bytes_read == state->size)
{ {
size_t sizeof_msg = 8192; char msg[8192];
char *msg = (char*)malloc(sizeof_msg * sizeof(char));
msg[0] = '\0'; msg[0] = '\0';
task_free_title(task); task_free_title(task);
if (state->autoload) if (state->autoload)
snprintf(msg, sizeof_msg, snprintf(msg, sizeof(msg),
"%s \"%s\" %s.", "%s \"%s\" %s.",
msg_hash_to_str(MSG_AUTOLOADING_SAVESTATE_FROM), msg_hash_to_str(MSG_AUTOLOADING_SAVESTATE_FROM),
state->path, state->path,
@ -908,9 +906,9 @@ static void task_load_handler(retro_task_t *task)
{ {
if (state->state_slot < 0) if (state->state_slot < 0)
strlcpy(msg, msg_hash_to_str(MSG_LOADED_STATE_FROM_SLOT_AUTO), strlcpy(msg, msg_hash_to_str(MSG_LOADED_STATE_FROM_SLOT_AUTO),
sizeof_msg); sizeof(msg));
else else
snprintf(msg, sizeof_msg, snprintf(msg, sizeof(msg),
msg_hash_to_str(MSG_LOADED_STATE_FROM_SLOT), msg_hash_to_str(MSG_LOADED_STATE_FROM_SLOT),
state->state_slot); state->state_slot);
@ -919,7 +917,6 @@ static void task_load_handler(retro_task_t *task)
if (!task_get_mute(task)) if (!task_get_mute(task))
task_set_title(task, strdup(msg)); task_set_title(task, strdup(msg));
free(msg);
task_load_handler_finished(task, state); task_load_handler_finished(task, state);
return; return;
@ -1581,40 +1578,31 @@ static bool dump_to_file_desperate(const void *data,
{ {
time_t time_; time_t time_;
struct tm tm_; struct tm tm_;
char *timebuf; char timebuf[256];
char *path; char path[PATH_MAX_LENGTH];
char *application_data = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char application_data[PATH_MAX_LENGTH];
application_data[0] = '\0'; application_data[0] = '\0';
path [0] = '\0';
timebuf [0] = '\0';
if (!fill_pathname_application_data(application_data, if (!fill_pathname_application_data(application_data,
PATH_MAX_LENGTH * sizeof(char))) sizeof(application_data)))
{
free(application_data);
return false; return false;
}
time(&time_); time(&time_);
timebuf = (char*)malloc(256 * sizeof(char));
timebuf[0] = '\0';
rtime_localtime(&time_, &tm_); rtime_localtime(&time_, &tm_);
strftime(timebuf, strftime(timebuf,
256 * sizeof(char), 256 * sizeof(char),
"%Y-%m-%d-%H-%M-%S", &tm_); "%Y-%m-%d-%H-%M-%S", &tm_);
path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); snprintf(path, sizeof(path),
path[0] = '\0';
snprintf(path,
PATH_MAX_LENGTH * sizeof(char),
"%s/RetroArch-recovery-%u%s", "%s/RetroArch-recovery-%u%s",
application_data, type, application_data, type,
timebuf); timebuf);
free(application_data);
free(timebuf);
/* Fallback (emergency) saves are always /* Fallback (emergency) saves are always
* uncompressed * uncompressed
* > If a regular save fails, then the host * > If a regular save fails, then the host
@ -1625,13 +1613,9 @@ static bool dump_to_file_desperate(const void *data,
* complicate matters by introducing zlib * complicate matters by introducing zlib
* compression overheads */ * compression overheads */
if (!filestream_write_file(path, data, size)) if (!filestream_write_file(path, data, size))
{
free(path);
return false; return false;
}
RARCH_WARN("[SRAM]: Succeeded in saving RAM data to \"%s\".\n", path); RARCH_WARN("[SRAM]: Succeeded in saving RAM data to \"%s\".\n", path);
free(path);
return true; return true;
} }
@ -1733,8 +1717,7 @@ bool event_load_save_files(bool is_sram_load_disabled)
void path_init_savefile_rtc(const char *savefile_path) void path_init_savefile_rtc(const char *savefile_path)
{ {
union string_list_elem_attr attr; union string_list_elem_attr attr;
char *savefile_name_rtc = (char*) char savefile_name_rtc[PATH_MAX_LENGTH];
malloc(PATH_MAX_LENGTH * sizeof(char));
savefile_name_rtc[0] = '\0'; savefile_name_rtc[0] = '\0';
@ -1745,9 +1728,8 @@ void path_init_savefile_rtc(const char *savefile_path)
attr.i = RETRO_MEMORY_RTC; attr.i = RETRO_MEMORY_RTC;
fill_pathname(savefile_name_rtc, fill_pathname(savefile_name_rtc,
savefile_path, ".rtc", savefile_path, ".rtc",
PATH_MAX_LENGTH * sizeof(char)); sizeof(savefile_name_rtc));
string_list_append(task_save_files, savefile_name_rtc, attr); string_list_append(task_save_files, savefile_name_rtc, attr);
free(savefile_name_rtc);
} }
void path_deinit_savefile(void) void path_deinit_savefile(void)