Cut down on some callocs

This commit is contained in:
twinaphex 2020-06-27 16:36:08 +02:00
parent ecc41fc59c
commit 408f40f413
4 changed files with 45 additions and 31 deletions

View file

@ -402,7 +402,7 @@ runtime_log_t *runtime_log_init(
/* Phew... If we get this far then all is well.
* > Create 'runtime_log' object */
runtime_log = (runtime_log_t*)calloc(1, sizeof(*runtime_log));
runtime_log = (runtime_log_t*)malloc(sizeof(*runtime_log));
if (!runtime_log)
return NULL;
@ -418,6 +418,8 @@ runtime_log_t *runtime_log_init(
runtime_log->last_played.minute = 0;
runtime_log->last_played.second = 0;
runtime_log->path[0] = '\0';
strlcpy(runtime_log->path, log_file_path, sizeof(runtime_log->path));
/* Load existing log file, if it exists */

View file

@ -33,29 +33,7 @@
RETRO_BEGIN_DECLS
typedef struct
{
unsigned hours;
unsigned minutes;
unsigned seconds;
} rtl_runtime_t;
typedef struct
{
unsigned year;
unsigned month;
unsigned day;
unsigned hour;
unsigned minute;
unsigned second;
} rtl_last_played_t;
typedef struct
{
rtl_runtime_t runtime;
rtl_last_played_t last_played;
char path[PATH_MAX_LENGTH];
} runtime_log_t;
/* Enums */
enum playlist_sublabel_last_played_style_type
{
@ -102,6 +80,32 @@ enum playlist_sublabel_runtime
PLAYLIST_RUNTIME_LAST
};
/* Structs */
typedef struct
{
unsigned hours;
unsigned minutes;
unsigned seconds;
} rtl_runtime_t;
typedef struct
{
unsigned year;
unsigned month;
unsigned day;
unsigned hour;
unsigned minute;
unsigned second;
} rtl_last_played_t;
typedef struct
{
rtl_runtime_t runtime;
rtl_last_played_t last_played;
char path[PATH_MAX_LENGTH];
} runtime_log_t;
/* Initialisation */
/* Initialise runtime log, loading current parameters

View file

@ -275,13 +275,19 @@ static void* task_push_http_transfer_generic(
if (!conn)
return NULL;
http = (http_handle_t*)calloc(1, sizeof(*http));
http = (http_handle_t*)malloc(sizeof(*http));
if (!http)
goto error;
http->connection.handle = conn;
http->connection.cb = &cb_http_conn_default;
http->connection.handle = conn;
http->connection.cb = &cb_http_conn_default;
http->connection.elem1[0] = '\0';
http->connection.url[0] = '\0';
http->handle = NULL;
http->cb = NULL;
http->status = 0;
http->error = false;
if (type)
strlcpy(http->connection.elem1, type, sizeof(http->connection.elem1));

View file

@ -257,15 +257,17 @@ static void download_pl_thumbnail(pl_thumb_handle_t *pl_thumb)
/* Only download missing thumbnails */
if (!path_is_valid(path) || pl_thumb->overwrite)
{
file_transfer_t *transf = (file_transfer_t*)calloc(1, sizeof(file_transfer_t));
file_transfer_t *transf = (file_transfer_t*)malloc(sizeof(file_transfer_t));
if (!transf)
return; /* If this happens then everything is broken anyway... */
/* Initialise http task status */
pl_thumb->http_task_complete = false;
transf->enum_idx = MSG_UNKNOWN;
transf->path[0] = '\0';
/* Initialise file transfer */
transf->user_data = (void*)pl_thumb;
transf->user_data = (void*)pl_thumb;
strlcpy(transf->path, path, sizeof(transf->path));
/* Note: We don't actually care if this fails since that
@ -478,9 +480,9 @@ bool task_push_pl_thumbnail_download(
const char *dir_thumbnails)
{
task_finder_data_t find_data;
const char *playlist_file = NULL;
retro_task_t *task = task_init();
pl_thumb_handle_t *pl_thumb = (pl_thumb_handle_t*)calloc(1, sizeof(pl_thumb_handle_t));
const char *playlist_file = NULL;
/* Sanity check */
if (!playlist_config || !task || !pl_thumb)
@ -787,7 +789,7 @@ bool task_push_pl_entry_thumbnail_download(
settings_t *settings = config_get_ptr();
retro_task_t *task = task_init();
pl_thumb_handle_t *pl_thumb = (pl_thumb_handle_t*)calloc(1, sizeof(pl_thumb_handle_t));
pl_entry_id_t *entry_id = (pl_entry_id_t*)calloc(1, sizeof(pl_entry_id_t));
pl_entry_id_t *entry_id = (pl_entry_id_t*)malloc(sizeof(pl_entry_id_t));
char *playlist_path = NULL;
gfx_thumbnail_path_data_t *
thumbnail_path_data = NULL;