mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 03:32:46 +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(
|
static void core_info_list_resolve_all_extensions(
|
||||||
core_info_list_t *core_info_list)
|
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)
|
if (!core_info_list)
|
||||||
return;
|
return;
|
||||||
@ -58,11 +60,13 @@ static void core_info_list_resolve_all_extensions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (all_ext_len)
|
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;
|
return;
|
||||||
|
|
||||||
|
core_info_list->all_ext = all_ext;
|
||||||
|
|
||||||
for (i = 0; i < core_info_list->count; i++)
|
for (i = 0; i < core_info_list->count; i++)
|
||||||
{
|
{
|
||||||
if (!core_info_list->list[i].supported_extensions)
|
if (!core_info_list->list[i].supported_extensions)
|
||||||
@ -80,24 +84,23 @@ static void core_info_list_resolve_all_firmware(
|
|||||||
size_t i;
|
size_t i;
|
||||||
unsigned c;
|
unsigned c;
|
||||||
|
|
||||||
if (!core_info_list)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (i = 0; i < core_info_list->count; i++)
|
for (i = 0; i < core_info_list->count; i++)
|
||||||
{
|
{
|
||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
core_info_t *info = (core_info_t*)&core_info_list->list[i];
|
core_info_firmware_t *firmware = NULL;
|
||||||
config_file_t *config = (config_file_t*)info->config_data;
|
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))
|
if (!config || !config_get_uint(config, "firmware_count", &count))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
info->firmware = (core_info_firmware_t*)
|
firmware = (core_info_firmware_t*)calloc(count, sizeof(*firmware));
|
||||||
calloc(count, sizeof(*info->firmware));
|
|
||||||
|
|
||||||
if (!info->firmware)
|
if (!firmware)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
info->firmware = firmware;
|
||||||
|
|
||||||
for (c = 0; c < count; c++)
|
for (c = 0; c < count; c++)
|
||||||
{
|
{
|
||||||
char path_key[64];
|
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_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);
|
dir_list_free(contents);
|
||||||
return core_info_list;
|
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,
|
memmove(playlist->entries + 1, playlist->entries,
|
||||||
(playlist->cap - 1) * sizeof(struct playlist_entry));
|
(playlist->cap - 1) * sizeof(struct playlist_entry));
|
||||||
|
|
||||||
playlist->entries[0].path = NULL;
|
playlist->entries[0].path = NULL;
|
||||||
playlist->entries[0].label = NULL;
|
playlist->entries[0].label = NULL;
|
||||||
playlist->entries[0].core_path = NULL;
|
playlist->entries[0].core_path = NULL;
|
||||||
playlist->entries[0].core_name = NULL;
|
playlist->entries[0].core_name = NULL;
|
||||||
playlist->entries[0].db_name = NULL;
|
playlist->entries[0].db_name = NULL;
|
||||||
playlist->entries[0].crc32 = NULL;
|
playlist->entries[0].crc32 = NULL;
|
||||||
if (!string_is_empty(path))
|
if (!string_is_empty(path))
|
||||||
playlist->entries[0].path = strdup(path);
|
playlist->entries[0].path = strdup(path);
|
||||||
if (!string_is_empty(label))
|
if (!string_is_empty(label))
|
||||||
playlist->entries[0].label = strdup(label);
|
playlist->entries[0].label = strdup(label);
|
||||||
if (!string_is_empty(core_path))
|
if (!string_is_empty(core_path))
|
||||||
playlist->entries[0].core_path = strdup(core_path);
|
playlist->entries[0].core_path = strdup(core_path);
|
||||||
if (!string_is_empty(core_name))
|
if (!string_is_empty(core_name))
|
||||||
@ -507,26 +507,25 @@ end:
|
|||||||
**/
|
**/
|
||||||
playlist_t *playlist_init(const char *path, size_t size)
|
playlist_t *playlist_init(const char *path, size_t size)
|
||||||
{
|
{
|
||||||
playlist_t *playlist = (playlist_t*)
|
struct playlist_entry *entries = NULL;
|
||||||
calloc(1, sizeof(*playlist));
|
playlist_t *playlist = (playlist_t*)calloc(1, sizeof(*playlist));
|
||||||
if (!playlist)
|
if (!playlist)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
playlist->entries = (struct playlist_entry*)calloc(size,
|
entries = (struct playlist_entry*)calloc(size, sizeof(*entries));
|
||||||
sizeof(*playlist->entries));
|
if (!entries)
|
||||||
if (!playlist->entries)
|
{
|
||||||
goto error;
|
free(playlist);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
playlist->cap = size;
|
playlist->entries = entries;
|
||||||
|
playlist->cap = size;
|
||||||
|
|
||||||
playlist_read_file(playlist, path);
|
playlist_read_file(playlist, path);
|
||||||
|
|
||||||
playlist->conf_path = strdup(path);
|
playlist->conf_path = strdup(path);
|
||||||
return playlist;
|
return playlist;
|
||||||
|
|
||||||
error:
|
|
||||||
playlist_free(playlist);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int playlist_qsort_func(const struct playlist_entry *a,
|
static int playlist_qsort_func(const struct playlist_entry *a,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user