mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-23 16:09:47 +00:00
Be more careful with allocation and assignment
This commit is contained in:
parent
17609e1d42
commit
2156bb43a1
31
core_info.c
31
core_info.c
@ -45,7 +45,9 @@ static core_info_list_t *core_info_curr_list = NULL;
|
||||
static void core_info_list_resolve_all_extensions(
|
||||
core_info_list_t *core_info_list)
|
||||
{
|
||||
size_t i, all_ext_len = 0;
|
||||
size_t i = 0;
|
||||
size_t all_ext_len = 0;
|
||||
char *all_ext = NULL;
|
||||
|
||||
if (!core_info_list)
|
||||
return;
|
||||
@ -58,11 +60,13 @@ static void core_info_list_resolve_all_extensions(
|
||||
}
|
||||
|
||||
if (all_ext_len)
|
||||
core_info_list->all_ext = (char*)calloc(1, all_ext_len);
|
||||
all_ext = (char*)calloc(1, all_ext_len);
|
||||
|
||||
if (!core_info_list->all_ext)
|
||||
if (!all_ext)
|
||||
return;
|
||||
|
||||
core_info_list->all_ext = all_ext;
|
||||
|
||||
for (i = 0; i < core_info_list->count; i++)
|
||||
{
|
||||
if (!core_info_list->list[i].supported_extensions)
|
||||
@ -80,24 +84,23 @@ static void core_info_list_resolve_all_firmware(
|
||||
size_t i;
|
||||
unsigned c;
|
||||
|
||||
if (!core_info_list)
|
||||
return;
|
||||
|
||||
for (i = 0; i < core_info_list->count; i++)
|
||||
{
|
||||
unsigned count = 0;
|
||||
core_info_t *info = (core_info_t*)&core_info_list->list[i];
|
||||
config_file_t *config = (config_file_t*)info->config_data;
|
||||
unsigned count = 0;
|
||||
core_info_firmware_t *firmware = NULL;
|
||||
core_info_t *info = (core_info_t*)&core_info_list->list[i];
|
||||
config_file_t *config = (config_file_t*)info->config_data;
|
||||
|
||||
if (!config || !config_get_uint(config, "firmware_count", &count))
|
||||
continue;
|
||||
|
||||
info->firmware = (core_info_firmware_t*)
|
||||
calloc(count, sizeof(*info->firmware));
|
||||
firmware = (core_info_firmware_t*)calloc(count, sizeof(*firmware));
|
||||
|
||||
if (!info->firmware)
|
||||
if (!firmware)
|
||||
continue;
|
||||
|
||||
info->firmware = firmware;
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
{
|
||||
char path_key[64];
|
||||
@ -366,7 +369,9 @@ static core_info_list_t *core_info_list_new(const char *path)
|
||||
}
|
||||
|
||||
core_info_list_resolve_all_extensions(core_info_list);
|
||||
core_info_list_resolve_all_firmware(core_info_list);
|
||||
|
||||
if (core_info_list)
|
||||
core_info_list_resolve_all_firmware(core_info_list);
|
||||
|
||||
dir_list_free(contents);
|
||||
return core_info_list;
|
||||
|
37
playlist.c
37
playlist.c
@ -310,16 +310,16 @@ bool playlist_push(playlist_t *playlist,
|
||||
memmove(playlist->entries + 1, playlist->entries,
|
||||
(playlist->cap - 1) * sizeof(struct playlist_entry));
|
||||
|
||||
playlist->entries[0].path = NULL;
|
||||
playlist->entries[0].label = NULL;
|
||||
playlist->entries[0].core_path = NULL;
|
||||
playlist->entries[0].core_name = NULL;
|
||||
playlist->entries[0].db_name = NULL;
|
||||
playlist->entries[0].crc32 = NULL;
|
||||
playlist->entries[0].path = NULL;
|
||||
playlist->entries[0].label = NULL;
|
||||
playlist->entries[0].core_path = NULL;
|
||||
playlist->entries[0].core_name = NULL;
|
||||
playlist->entries[0].db_name = NULL;
|
||||
playlist->entries[0].crc32 = NULL;
|
||||
if (!string_is_empty(path))
|
||||
playlist->entries[0].path = strdup(path);
|
||||
playlist->entries[0].path = strdup(path);
|
||||
if (!string_is_empty(label))
|
||||
playlist->entries[0].label = strdup(label);
|
||||
playlist->entries[0].label = strdup(label);
|
||||
if (!string_is_empty(core_path))
|
||||
playlist->entries[0].core_path = strdup(core_path);
|
||||
if (!string_is_empty(core_name))
|
||||
@ -507,26 +507,25 @@ end:
|
||||
**/
|
||||
playlist_t *playlist_init(const char *path, size_t size)
|
||||
{
|
||||
playlist_t *playlist = (playlist_t*)
|
||||
calloc(1, sizeof(*playlist));
|
||||
struct playlist_entry *entries = NULL;
|
||||
playlist_t *playlist = (playlist_t*)calloc(1, sizeof(*playlist));
|
||||
if (!playlist)
|
||||
return NULL;
|
||||
|
||||
playlist->entries = (struct playlist_entry*)calloc(size,
|
||||
sizeof(*playlist->entries));
|
||||
if (!playlist->entries)
|
||||
goto error;
|
||||
entries = (struct playlist_entry*)calloc(size, sizeof(*entries));
|
||||
if (!entries)
|
||||
{
|
||||
free(playlist);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
playlist->cap = size;
|
||||
playlist->entries = entries;
|
||||
playlist->cap = size;
|
||||
|
||||
playlist_read_file(playlist, path);
|
||||
|
||||
playlist->conf_path = strdup(path);
|
||||
return playlist;
|
||||
|
||||
error:
|
||||
playlist_free(playlist);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int playlist_qsort_func(const struct playlist_entry *a,
|
||||
|
Loading…
Reference in New Issue
Block a user