Revert "New attempt to fix memory leaks of struct retro_system_info"

This reverts commit a1d3dd69dd51ba21b07e9fb96cd1a7d05f435974.
This commit is contained in:
twinaphex 2017-05-30 01:44:49 +02:00
parent 0066fe8065
commit 449483206f
20 changed files with 109 additions and 157 deletions

View File

@ -1645,7 +1645,7 @@ bool command_event(enum event_command cmd, void *data)
#ifdef HAVE_MENU
core_info_ctx_find_t info_find;
rarch_system_info_t *system_info = runloop_get_system_info();
struct retro_system_info_internal *system = &system_info->info_int;
struct retro_system_info *system = &system_info->info;
#if defined(HAVE_DYNAMIC)
if (string_is_empty(path_get(RARCH_PATH_CORE)))

View File

@ -2715,7 +2715,7 @@ bool config_load_override(void)
rarch_system_info_t *system = runloop_get_system_info();
if (system)
core_name = system->info_int.library_name;
core_name = system->info.library_name;
game_name = path_basename(path_get(RARCH_PATH_BASENAME));
@ -2870,7 +2870,7 @@ bool config_load_remap(void)
rarch_system_info_t *system = runloop_get_system_info();
if (system)
core_name = system->info_int.library_name;
core_name = system->info.library_name;
game_name = path_basename(path_get(RARCH_PATH_BASENAME));
@ -2970,7 +2970,7 @@ bool config_load_shader_preset(void)
rarch_system_info_t *system = runloop_get_system_info();
if (system)
core_name = system->info_int.library_name;
core_name = system->info.library_name;
game_name = path_basename(path_get(RARCH_PATH_BASENAME));
@ -3605,7 +3605,7 @@ bool config_save_overrides(int override_type)
rarch_system_info_t *system = runloop_get_system_info();
if (system)
core_name = system->info_int.library_name;
core_name = system->info.library_name;
game_name = path_basename(path_get(RARCH_PATH_BASENAME));

39
core.h
View File

@ -54,48 +54,9 @@ typedef struct rarch_memory_map
unsigned num_descriptors;
} rarch_memory_map_t;
struct retro_system_info_internal
{
/* All pointers are owned by libretro implementation, and pointers must
* remain valid until retro_deinit() is called. */
char *library_name; /* Descriptive name of library. Should not
* contain any version numbers, etc. */
char *library_version; /* Descriptive version of core. */
char *valid_extensions; /* A string listing probably content
* extensions the core will be able to
* load, separated with pipe.
* I.e. "bin|rom|iso".
* Typically used for a GUI to filter
* out extensions. */
/* If true, retro_load_game() is guaranteed to provide a valid pathname
* in retro_game_info::path.
* ::data and ::size are both invalid.
*
* If false, ::data and ::size are guaranteed to be valid, but ::path
* might not be valid.
*
* This is typically set to true for libretro implementations that must
* load from file.
* Implementations should strive for setting this to false, as it allows
* the frontend to perform patching, etc. */
bool need_fullpath;
/* If true, the frontend is not allowed to extract any archives before
* loading the real content.
* Necessary for certain libretro implementations that load games
* from zipped archives. */
bool block_extract;
};
typedef struct rarch_system_info
{
struct retro_system_info_internal info_int;
#if 0
struct retro_system_info info;
#endif
unsigned rotation;
unsigned performance_level;

View File

@ -145,21 +145,14 @@ libretro_find_controller_description(
*
* Frees system information.
**/
void libretro_free_system_info(struct retro_system_info_internal *info)
void libretro_free_system_info(struct retro_system_info *info)
{
if (!info)
return;
if (info->library_name != NULL)
free(info->library_name);
if (info->library_version != NULL)
free(info->library_version);
if (info->valid_extensions != NULL)
free(info->valid_extensions);
info->library_name = NULL;
info->library_version = NULL;
info->valid_extensions = NULL;
free((void*)info->library_name);
free((void*)info->library_version);
free((void*)info->valid_extensions);
memset(info, 0, sizeof(*info));
}
@ -318,7 +311,7 @@ static dylib_t libretro_get_system_info_lib(const char *path,
* Returns: true (1) if successful, otherwise false (0).
**/
bool libretro_get_system_info(const char *path,
struct retro_system_info_internal *info, bool *load_no_content)
struct retro_system_info *info, bool *load_no_content)
{
struct retro_system_info dummy_info;
#ifdef HAVE_DYNAMIC
@ -359,23 +352,13 @@ bool libretro_get_system_info(const char *path,
retro_get_system_info(&dummy_info);
#endif
if (info->library_name != NULL)
free(info->library_name);
if (info->library_version != NULL)
free(info->library_version);
if (info->valid_extensions != NULL)
free(info->valid_extensions);
info->need_fullpath = dummy_info.need_fullpath;
info->block_extract = dummy_info.block_extract;
info->library_version = NULL;
info->library_name = NULL;
info->valid_extensions = NULL;
memcpy(info, &dummy_info, sizeof(*info));
if (!string_is_empty(dummy_info.library_name))
info->library_name = strdup(dummy_info.library_name);
if (!string_is_empty(dummy_info.library_version))
info->library_version = strdup(dummy_info.library_version);
if (dummy_info.valid_extensions)
info->valid_extensions = strdup(dummy_info.valid_extensions);

View File

@ -21,7 +21,6 @@
#include <retro_common_api.h>
#include <libretro.h>
#include "core.h"
#include "core_type.h"
RETRO_BEGIN_DECLS
@ -39,7 +38,7 @@ RETRO_BEGIN_DECLS
* Returns: true (1) if successful, otherwise false (0).
**/
bool libretro_get_system_info(const char *path,
struct retro_system_info_internal *info, bool *load_no_content);
struct retro_system_info *info, bool *load_no_content);
/**
* libretro_free_system_info:
@ -47,7 +46,7 @@ bool libretro_get_system_info(const char *path,
*
* Frees system information.
**/
void libretro_free_system_info(struct retro_system_info_internal *info);
void libretro_free_system_info(struct retro_system_info *info);
const struct retro_subsystem_info *libretro_find_subsystem_info(
const struct retro_subsystem_info *info,

View File

@ -618,7 +618,7 @@ static int general_push(menu_displaylist_info_t *info,
core_info_list_t *list = NULL;
menu_handle_t *menu = NULL;
rarch_system_info_t *system = runloop_get_system_info();
struct retro_system_info_internal *system_menu = &system->info_int;
struct retro_system_info *system_menu = &system->info;
if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu))
return menu_cbs_exit();

View File

@ -1379,7 +1379,7 @@ static int action_ok_playlist_entry_collection(const char *path,
playlist_t *tmp_playlist = NULL;
menu_handle_t *menu = NULL;
rarch_system_info_t *info = runloop_get_system_info();
struct retro_system_info_internal *system = &info->info_int;
struct retro_system_info *system = &info->info;
content_info.argc = 0;
content_info.argv = NULL;
@ -1958,12 +1958,14 @@ static int generic_action_ok_shader_preset_save(const char *path,
char file[PATH_MAX_LENGTH];
char tmp[PATH_MAX_LENGTH];
settings_t *settings = config_get_ptr();
const char *core_name = NULL;
rarch_system_info_t *info = runloop_get_system_info();
struct retro_system_info_internal *system = &info->info_int;
const char *core_name = system ? system->library_name : NULL;
directory[0] = file[0] = tmp[0] = '\0';
if (info)
core_name = info->info.library_name;
if (!string_is_empty(core_name))
{
fill_pathname_join(
@ -2073,12 +2075,14 @@ static int generic_action_ok_remap_file_save(const char *path,
char directory[PATH_MAX_LENGTH];
char file[PATH_MAX_LENGTH];
settings_t *settings = config_get_ptr();
const char *core_name = NULL;
rarch_system_info_t *info = runloop_get_system_info();
struct retro_system_info_internal *system = &info->info_int;
const char *core_name = system ? system->library_name : NULL;
directory[0] = file[0] = '\0';
if (info)
core_name = info->info.library_name;
if (!string_is_empty(core_name))
fill_pathname_join(
directory,

View File

@ -857,7 +857,7 @@ static int mui_get_core_title(char *s, size_t len)
const char *core_name = NULL;
const char *core_version = NULL;
rarch_system_info_t *info = runloop_get_system_info();
struct retro_system_info_internal *system = &info->info_int;
struct retro_system_info *system = &info->info;
core_name = system->library_name;
core_version = system->library_version;
@ -868,9 +868,9 @@ static int mui_get_core_title(char *s, size_t len)
if (info)
{
if (string_is_empty(core_name))
core_name = info->info_int.library_name;
core_name = info->info.library_name;
if (!core_version)
core_version = info->info_int.library_version;
core_version = info->info.library_version;
}
if (string_is_empty(core_name))
@ -1807,8 +1807,8 @@ static int mui_list_push(void *data, void *userdata,
entry.parse_type = PARSE_ACTION;
entry.add_empty_entry = false;
if (!string_is_empty(system->info_int.library_name) &&
!string_is_equal(system->info_int.library_name,
if (!string_is_empty(system->info.library_name) &&
!string_is_equal(system->info.library_name,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_CORE)))
{
entry.enum_idx = MENU_ENUM_LABEL_CONTENT_SETTINGS;

View File

@ -4038,8 +4038,8 @@ static int xmb_list_push(void *data, void *userdata,
entry.parse_type = PARSE_ACTION;
entry.add_empty_entry = false;
if (!string_is_empty(system->info_int.library_name) &&
!string_is_equal(system->info_int.library_name,
if (!string_is_empty(system->info.library_name) &&
!string_is_equal(system->info.library_name,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_CORE)))
{
entry.enum_idx = MENU_ENUM_LABEL_CONTENT_SETTINGS;

View File

@ -2990,8 +2990,8 @@ static int menu_displaylist_parse_information_list(
core_info_get_current_core(&core_info);
if ( system &&
(!string_is_empty(system->info_int.library_name) &&
!string_is_equal(system->info_int.library_name,
(!string_is_empty(system->info.library_name) &&
!string_is_equal(system->info.library_name,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_CORE))
)
&& core_info && core_info->config_data
@ -4477,7 +4477,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
if (cores_names_size == 0)
{
rarch_system_info_t *system_info = runloop_get_system_info();
struct retro_system_info_internal *system = &system_info->info_int;
struct retro_system_info *system = &system_info->info;
const char *core_name = system ? system->library_name : NULL;
if (!path_is_empty(RARCH_PATH_CORE))
@ -4591,7 +4591,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
{
const char *core_name = NULL;
rarch_system_info_t *system_info = runloop_get_system_info();
struct retro_system_info_internal *system = &system_info->info_int;
struct retro_system_info *system = &system_info->info;
if (system)
core_name = system->library_name;
@ -6000,8 +6000,8 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
if (system)
{
if ( !string_is_empty(system->info_int.library_name) &&
!string_is_equal(system->info_int.library_name,
if ( !string_is_empty(system->info.library_name) &&
!string_is_equal(system->info.library_name,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_CORE)))
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_CONTENT_SETTINGS,

View File

@ -1826,8 +1826,8 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data)
#endif
{
rarch_system_info_t *system = runloop_get_system_info();
libretro_free_system_info(&system->info_int);
memset(&system->info_int, 0, sizeof(struct retro_system_info_internal));
libretro_free_system_info(&system->info);
memset(&system->info, 0, sizeof(struct retro_system_info));
}
video_coord_array_free(&menu_disp_ca);

View File

@ -266,12 +266,15 @@ int menu_entries_get_title(char *s, size_t len)
int menu_entries_get_core_name(char *s, size_t len)
{
rarch_system_info_t *info = runloop_get_system_info();
struct retro_system_info_internal
*system = &info->info_int;
const char *core_name = system ? system->library_name : NULL;
struct retro_system_info *system = &info->info;
const char *core_name = NULL;
if (string_is_empty(core_name) || string_is_equal(core_name,
msg_hash_to_str(MSG_UNKNOWN)))
if (system)
core_name = system->library_name;
if (string_is_empty(core_name) && info)
core_name = info->info.library_name;
if (string_is_empty(core_name))
core_name = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_CORE);
snprintf(s, len, "%s", core_name);
@ -297,13 +300,24 @@ bool menu_entries_current_core_is_no_core(void)
* (shown at the top of the UI). */
int menu_entries_get_core_title(char *s, size_t len)
{
const char *core_name = NULL;
const char *core_version = NULL;
rarch_system_info_t *info = runloop_get_system_info();
struct retro_system_info_internal *system = &info->info_int;
const char *core_name = system ? system->library_name : NULL;
const char *core_version = system ? system->library_version : NULL;
struct retro_system_info *system = &info->info;
if (system)
{
core_name = system->library_name;
core_version = system->library_version;
}
if (string_is_empty(core_name) && info)
core_name = info->info.library_name;
if (string_is_empty(core_name))
core_name = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_CORE);
if (!core_version && info)
core_version = info->info.library_version;
if (!core_version)
core_version = "";

View File

@ -269,9 +269,9 @@ bool netplay_lan_ad_server(netplay_t *netplay)
if (info)
{
strlcpy(ad_packet_buffer.core, info->info_int.library_name,
strlcpy(ad_packet_buffer.core, info->info.library_name,
NETPLAY_HOST_STR_LEN);
strlcpy(ad_packet_buffer.core_version, info->info_int.library_version,
strlcpy(ad_packet_buffer.core_version, info->info.library_version,
NETPLAY_HOST_STR_LEN);
}

View File

@ -610,9 +610,9 @@ static void netplay_announce(void)
uint32_t content_crc = content_get_crc();
net_http_urlencode_full(&username, settings->paths.username);
net_http_urlencode_full(&corename, system->info_int.library_name);
net_http_urlencode_full(&corename, system->info.library_name);
net_http_urlencode_full(&gamename, !string_is_empty(path_basename(path_get(RARCH_PATH_BASENAME))) ? path_basename(path_get(RARCH_PATH_BASENAME)) : "N/A");
net_http_urlencode_full(&coreversion, system->info_int.library_version);
net_http_urlencode_full(&coreversion, system->info.library_version);
buf[0] = '\0';

View File

@ -488,9 +488,9 @@ bool netplay_handshake_info(netplay_t *netplay,
if (core_info)
{
strlcpy(info_buf.core_name,
core_info->info_int.library_name, sizeof(info_buf.core_name));
core_info->info.library_name, sizeof(info_buf.core_name));
strlcpy(info_buf.core_version,
core_info->info_int.library_version, sizeof(info_buf.core_version));
core_info->info.library_version, sizeof(info_buf.core_version));
}
else
{
@ -834,9 +834,9 @@ bool netplay_handshake_pre_info(netplay_t *netplay,
if (core_info)
{
if (strncmp(info_buf.core_name,
core_info->info_int.library_name, sizeof(info_buf.core_name)) ||
core_info->info.library_name, sizeof(info_buf.core_name)) ||
strncmp(info_buf.core_version,
core_info->info_int.library_version, sizeof(info_buf.core_version)))
core_info->info.library_version, sizeof(info_buf.core_version)))
{
dmsg = msg_hash_to_str(MSG_NETPLAY_IMPLEMENTATIONS_DIFFER);
goto error;

13
paths.c
View File

@ -71,9 +71,10 @@ void path_set_redirect(void)
new_savefile_dir[0] = new_savestate_dir[0] = '\0';
if (info && !string_is_empty(info->info_int.library_name))
if (info && info->info.library_name &&
!string_is_empty(info->info.library_name))
library_name_hash =
msg_hash_calculate(info->info_int.library_name);
msg_hash_calculate(info->info.library_name);
/* Initialize current save directories
* with the values from the config. */
@ -102,7 +103,7 @@ void path_set_redirect(void)
fill_pathname_join(
new_savefile_dir,
old_savefile_dir,
info->info_int.library_name,
info->info.library_name,
sizeof(new_savefile_dir));
/* If path doesn't exist, try to create it,
@ -131,7 +132,7 @@ void path_set_redirect(void)
fill_pathname_join(
new_savestate_dir,
old_savestate_dir,
info->info_int.library_name,
info->info.library_name,
sizeof(new_savestate_dir));
/* If path doesn't exist, try to create it.
@ -175,7 +176,7 @@ void path_set_redirect(void)
{
fill_pathname_dir(global->name.savefile,
!string_is_empty(path_main_basename) ? path_main_basename :
info->info_int.library_name,
info->info.library_name,
file_path_str(FILE_PATH_SRM_EXTENSION),
sizeof(global->name.savefile));
RARCH_LOG("%s \"%s\".\n",
@ -187,7 +188,7 @@ void path_set_redirect(void)
{
fill_pathname_dir(global->name.savestate,
!string_is_empty(path_main_basename) ? path_main_basename :
info->info_int.library_name,
info->info.library_name,
file_path_str(FILE_PATH_STATE_EXTENSION),
sizeof(global->name.savestate));
RARCH_LOG("%s \"%s\".\n",

View File

@ -1098,7 +1098,7 @@ bool retroarch_validate_game_options(char *s, size_t len, bool mkdir)
char core_path[PATH_MAX_LENGTH];
char config_directory[PATH_MAX_LENGTH];
rarch_system_info_t *system = &runloop_system;
const char *core_name = system ? system->info_int.library_name : NULL;
const char *core_name = system ? system->info.library_name : NULL;
const char *game_name = path_basename(path_get(RARCH_PATH_BASENAME));
if (string_is_empty(core_name) || string_is_empty(game_name))
@ -1424,7 +1424,7 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
config_free();
break;
case RARCH_CTL_PREINIT:
libretro_free_system_info(&runloop_system.info_int);
libretro_free_system_info(&runloop_system.info);
command_event(CMD_EVENT_HISTORY_DEINIT, NULL);
config_init();
@ -1510,29 +1510,19 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
case RARCH_CTL_IS_BLOCK_CONFIG_READ:
return rarch_block_config_read;
case RARCH_CTL_SYSTEM_INFO_INIT:
{
struct retro_system_info system_info;
core_get_system_info(&runloop_system.info);
core_get_system_info(&system_info);
if (!runloop_system.info.library_name)
runloop_system.info.library_name = msg_hash_to_str(MSG_UNKNOWN);
if (!runloop_system.info.library_version)
runloop_system.info.library_version = "v0";
if (!string_is_empty(system_info.library_name))
runloop_system.info_int.library_name = strdup(system_info.library_name);
else
runloop_system.info_int.library_name = strdup(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_CORE));
video_driver_set_title_buf();
if (!string_is_empty(system_info.library_version))
runloop_system.info_int.library_version = strdup(system_info.library_version);
if (!string_is_empty(system_info.valid_extensions))
runloop_system.info_int.valid_extensions = strdup(system_info.valid_extensions);
else
runloop_system.info_int.valid_extensions = strdup(DEFAULT_EXT);
runloop_system.info_int.need_fullpath = system_info.need_fullpath;
runloop_system.info_int.block_extract = system_info.block_extract;
video_driver_set_title_buf();
}
strlcpy(runloop_system.valid_extensions,
runloop_system.info.valid_extensions ?
runloop_system.info.valid_extensions : DEFAULT_EXT,
sizeof(runloop_system.valid_extensions));
break;
case RARCH_CTL_GET_CORE_OPTION_SIZE:
{
@ -1575,18 +1565,18 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
audio_driver_unset_callback();
if (runloop_system.info_int.library_name != NULL)
free(runloop_system.info_int.library_name);
if (runloop_system.info_int.library_version != NULL)
free(runloop_system.info_int.library_version);
if (runloop_system.info_int.valid_extensions != NULL)
free(runloop_system.info_int.valid_extensions);
if (!string_is_empty(runloop_system.info.library_name))
free((void*)runloop_system.info.library_name);
if (!string_is_empty(runloop_system.info.library_version))
free((void*)runloop_system.info.library_version);
if (!string_is_empty(runloop_system.info.valid_extensions))
free((void*)runloop_system.info.valid_extensions);
runloop_system.info_int.library_name = NULL;
runloop_system.info_int.library_version = NULL;
runloop_system.info_int.valid_extensions = NULL;
runloop_system.info_int.need_fullpath = false;
runloop_system.info_int.block_extract = false;
runloop_system.info.library_name = NULL;
runloop_system.info.library_version = NULL;
runloop_system.info.valid_extensions = NULL;
runloop_system.info.need_fullpath = false;
runloop_system.info.block_extract = false;
memset(&runloop_system, 0, sizeof(rarch_system_info_t));
break;

View File

@ -842,13 +842,13 @@ static bool task_load_content(content_ctx_info_t *content_info,
if (is_inited || contentless)
{
char tmp[PATH_MAX_LENGTH];
struct retro_system_info_internal *info = NULL;
struct retro_system_info *info = NULL;
rarch_system_info_t *sys_info = runloop_get_system_info();
tmp[0] = '\0';
if (sys_info)
info = &sys_info->info_int;
info = &sys_info->info;
strlcpy(tmp, path_get(RARCH_PATH_CONTENT), sizeof(tmp));
@ -1725,11 +1725,11 @@ bool content_init(void)
content_ctx.directory_system = strdup(settings->paths.directory_system);
if (!string_is_empty(settings->paths.directory_cache))
content_ctx.directory_cache = strdup(settings->paths.directory_cache);
if (!string_is_empty(sys_info->info_int.valid_extensions))
content_ctx.valid_extensions = strdup(sys_info->info_int.valid_extensions);
if (!string_is_empty(sys_info->info.valid_extensions))
content_ctx.valid_extensions = strdup(sys_info->info.valid_extensions);
content_ctx.block_extract = sys_info->info_int.block_extract;
content_ctx.need_fullpath = sys_info->info_int.need_fullpath;
content_ctx.block_extract = sys_info->info.block_extract;
content_ctx.need_fullpath = sys_info->info.need_fullpath;
content_ctx.subsystem.data = sys_info->subsystem.data;
content_ctx.subsystem.size = sys_info->subsystem.size;

View File

@ -57,7 +57,7 @@ static void netplay_crc_scan_callback(void *task_data,
netplay_crc_handle_t *state = (netplay_crc_handle_t*)task_data;
content_ctx_info_t content_info = {0};
rarch_system_info_t *info = runloop_get_system_info();
struct retro_system_info_internal *system = &info->info_int;
struct retro_system_info *system = &info->info;
if (!state)
return;
@ -95,7 +95,7 @@ static void netplay_crc_scan_callback(void *task_data,
command_event(CMD_EVENT_NETPLAY_INIT_DIRECT_DEFERRED, state->hostname);
if (!string_is_equal(info->info_int.library_name, state->core_name))
if (!string_is_equal(info->info.library_name, state->core_name))
task_push_load_new_core(state->core_path, NULL,
&content_info, CORE_TYPE_PLAIN, NULL, NULL);

View File

@ -279,7 +279,7 @@ static char** waiting_argv;
if (filenames.count == 1 && [filenames objectAtIndex:0])
{
rarch_system_info_t *info = runloop_get_system_info();
struct retro_system_info_internal *system = &info->info_int;
struct retro_system_info *system = &info->info;
NSString *__core = [filenames objectAtIndex:0];
const char *core_name = NULL;
@ -355,7 +355,7 @@ static void open_document_handler(ui_browser_window_state_t *state, bool result)
return;
rarch_system_info_t *info = runloop_get_system_info();
struct retro_system_info_internal *system = &info->info_int;
struct retro_system_info *system = &info->info;
const char *core_name = NULL;
if (system)