diff --git a/core.h b/core.h index 40d0a193d4..ba69479b05 100644 --- a/core.h +++ b/core.h @@ -243,6 +243,8 @@ bool core_is_inited(void); bool core_is_game_loaded(void); +void core_free_retro_game_info(struct retro_game_info *dest); + extern struct retro_callbacks retro_ctx; RETRO_END_DECLS diff --git a/core_impl.c b/core_impl.c index 6de1482868..c43d4202eb 100644 --- a/core_impl.c +++ b/core_impl.c @@ -530,3 +530,18 @@ bool core_is_game_loaded(void) { return current_core.game_loaded; } + +void core_free_retro_game_info(struct retro_game_info *dest) +{ + if (!dest) + return; + if (dest->path) + free((void*)dest->path); + if (dest->data) + free((void*)dest->data); + if (dest->meta) + free((void*)dest->meta); + dest->path = NULL; + dest->data = NULL; + dest->meta = NULL; +} diff --git a/libretro-common/lists/string_list.c b/libretro-common/lists/string_list.c index 3a5fb96fef..a96dd2975a 100644 --- a/libretro-common/lists/string_list.c +++ b/libretro-common/lists/string_list.c @@ -42,8 +42,15 @@ void string_list_free(struct string_list *list) return; for (i = 0; i < list->size; i++) - free(list->elems[i].data); - free(list->elems); + { + if (list->elems[i].data) + free(list->elems[i].data); + list->elems[i].data = NULL; + } + + if (list->elems) + free(list->elems); + list->elems = NULL; free(list); } diff --git a/runahead/copy_load_info.c b/runahead/copy_load_info.c index d9d4dc7914..e17ffbbaab 100644 --- a/runahead/copy_load_info.c +++ b/runahead/copy_load_info.c @@ -11,21 +11,6 @@ retro_ctx_load_content_info_t *load_content_info; enum rarch_core_type last_core_type; -static void free_retro_game_info(struct retro_game_info *dest) -{ - if (!dest) - return; - if (dest->path) - free((void*)dest->path); - if (dest->data) - free((void*)dest->data); - if (dest->meta) - free((void*)dest->meta); - dest->path = NULL; - dest->data = NULL; - dest->meta = NULL; -} - static struct retro_game_info* clone_retro_game_info(const struct retro_game_info *src) { @@ -60,23 +45,6 @@ static struct retro_game_info* clone_retro_game_info(const return dest; } -static void free_string_list(struct string_list *dest) -{ - unsigned i; - if (!dest) - return; - for (i = 0; i < dest->size; i++) - { - if (dest->elems[i].data) - free(dest->elems[i].data); - dest->elems[i].data = NULL; - } - - if (dest->elems) - free(dest->elems); - dest->elems = NULL; -} - static struct string_list *string_list_clone( const struct string_list *src) { @@ -237,12 +205,10 @@ static void free_retro_ctx_load_content_info(struct if (!dest) return; - free_retro_game_info(dest->info); - free_string_list((struct string_list*)dest->content); + core_free_retro_game_info(dest->info); + string_list_free((struct string_list*)dest->content); if (dest->info) free(dest->info); - if (dest->content) - free((void*)dest->content); dest->info = NULL; dest->content = NULL; diff --git a/runahead/mem_util.c b/runahead/mem_util.c index d04e3097d9..3f0b3d16b4 100644 --- a/runahead/mem_util.c +++ b/runahead/mem_util.c @@ -2,49 +2,48 @@ #include "mem_util.h" -char *strcpy_alloc(const char *sourceStr) +char *strcpy_alloc(const char *src) { - size_t len = 0; char *result = NULL; - - if (sourceStr) - len = strlen(sourceStr); + size_t len = src ? strlen(src) : 0; if (len == 0) return NULL; result = (char*)malloc(len + 1); - strcpy(result, sourceStr); + strcpy(result, src); return result; } -char *strcpy_alloc_force(const char *sourceStr) +char *strcpy_alloc_force(const char *src) { - char *result = strcpy_alloc(sourceStr); + char *result = strcpy_alloc(src); if (!result) - result = (char*)calloc(1, 1); + return (char*)calloc(1, 1); return result; } -void strcat_alloc(char ** destStr_p, const char *appendStr) +void strcat_alloc(char **dst, const char *s) { - size_t len1, len2, newLen; - char *destStr = *destStr_p; + size_t len1; + char *src = *dst; - if (!destStr) + if (!src) { - destStr = strcpy_alloc_force(appendStr); - *destStr_p = destStr; + src = strcpy_alloc_force(s); + *dst = src; return; } - if (!appendStr) + if (!s) return; - len1 = strlen(destStr); - len2 = strlen(appendStr); - newLen = len1 + len2 + 1; - destStr = (char*)realloc(destStr, newLen); - *destStr_p = destStr; - strcpy(destStr + len1, appendStr); + len1 = strlen(src); + src = (char*)realloc(src, len1 + strlen(s) + 1); + + if (!src) + return; + + *dst = src; + strcpy(src + len1, s); }