mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 12:40:23 +00:00
Fix 17 new memory leaks catched by Coverity
This commit is contained in:
parent
d3933f04c6
commit
f06ea9ba70
@ -614,15 +614,11 @@ static void task_save_handler(retro_task_t *task)
|
|||||||
**/
|
**/
|
||||||
static void task_push_undo_save_state(const char *path, void *data, size_t size)
|
static void task_push_undo_save_state(const char *path, void *data, size_t size)
|
||||||
{
|
{
|
||||||
retro_task_t *task = (retro_task_t*)calloc(1, sizeof(*task));
|
retro_task_t *task = (retro_task_t*)calloc(1, sizeof(*task));
|
||||||
save_task_state_t *state = (save_task_state_t*)calloc(1, sizeof(*state));
|
save_task_state_t *state = (save_task_state_t*)calloc(1, sizeof(*state));
|
||||||
|
|
||||||
if (!task || !state)
|
if (!task || !state)
|
||||||
{
|
goto error;
|
||||||
if (data)
|
|
||||||
free(data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
strlcpy(state->path, path, sizeof(state->path));
|
strlcpy(state->path, path, sizeof(state->path));
|
||||||
state->data = data;
|
state->data = data;
|
||||||
@ -636,6 +632,14 @@ static void task_push_undo_save_state(const char *path, void *data, size_t size)
|
|||||||
task->title = strdup(msg_hash_to_str(MSG_UNDOING_SAVE_STATE));
|
task->title = strdup(msg_hash_to_str(MSG_UNDOING_SAVE_STATE));
|
||||||
|
|
||||||
task_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
|
task_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (data)
|
||||||
|
free(data);
|
||||||
|
if (task)
|
||||||
|
free(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -963,11 +967,7 @@ static void task_push_save_state(const char *path, void *data, size_t size)
|
|||||||
save_task_state_t *state = (save_task_state_t*)calloc(1, sizeof(*state));
|
save_task_state_t *state = (save_task_state_t*)calloc(1, sizeof(*state));
|
||||||
|
|
||||||
if (!task || !state)
|
if (!task || !state)
|
||||||
{
|
goto error;
|
||||||
if (data)
|
|
||||||
free(data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
strlcpy(state->path, path, sizeof(state->path));
|
strlcpy(state->path, path, sizeof(state->path));
|
||||||
state->data = data;
|
state->data = data;
|
||||||
@ -979,6 +979,14 @@ static void task_push_save_state(const char *path, void *data, size_t size)
|
|||||||
task->title = strdup(msg_hash_to_str(MSG_SAVING_STATE));
|
task->title = strdup(msg_hash_to_str(MSG_SAVING_STATE));
|
||||||
|
|
||||||
task_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
|
task_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (data)
|
||||||
|
free(data);
|
||||||
|
if (task)
|
||||||
|
free(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -991,9 +999,9 @@ static void content_load_and_save_state_cb(void *task_data,
|
|||||||
void *user_data, const char *error)
|
void *user_data, const char *error)
|
||||||
{
|
{
|
||||||
load_task_data_t *load_data = (load_task_data_t*)task_data;
|
load_task_data_t *load_data = (load_task_data_t*)task_data;
|
||||||
char *path = strdup(load_data->path);
|
char *path = strdup(load_data->path);
|
||||||
void *data = load_data->undo_data;
|
void *data = load_data->undo_data;
|
||||||
size_t size = load_data->undo_size;
|
size_t size = load_data->undo_size;
|
||||||
|
|
||||||
content_load_state_cb(task_data, user_data, error);
|
content_load_state_cb(task_data, user_data, error);
|
||||||
|
|
||||||
@ -1014,28 +1022,32 @@ static void content_load_and_save_state_cb(void *task_data,
|
|||||||
**/
|
**/
|
||||||
static void task_push_load_and_save_state(const char *path, void *data, size_t size, bool load_to_backup_buffer)
|
static void task_push_load_and_save_state(const char *path, void *data, size_t size, bool load_to_backup_buffer)
|
||||||
{
|
{
|
||||||
retro_task_t *task = (retro_task_t*)calloc(1, sizeof(*task));
|
retro_task_t *task = (retro_task_t*)calloc(1, sizeof(*task));
|
||||||
save_task_state_t *state = (save_task_state_t*)calloc(1, sizeof(*state));
|
save_task_state_t *state = (save_task_state_t*)calloc(1, sizeof(*state));
|
||||||
|
|
||||||
if (!task || !state)
|
if (!task || !state)
|
||||||
{
|
goto error;
|
||||||
if (data)
|
|
||||||
free(data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
strlcpy(state->path, path, sizeof(state->path));
|
strlcpy(state->path, path, sizeof(state->path));
|
||||||
state->load_to_backup_buffer = load_to_backup_buffer;
|
state->load_to_backup_buffer = load_to_backup_buffer;
|
||||||
state->undo_size = size;
|
state->undo_size = size;
|
||||||
state->undo_data = data;
|
state->undo_data = data;
|
||||||
|
|
||||||
task->state = state;
|
task->state = state;
|
||||||
task->type = TASK_TYPE_BLOCKING;
|
task->type = TASK_TYPE_BLOCKING;
|
||||||
task->handler = task_load_handler;
|
task->handler = task_load_handler;
|
||||||
task->callback = content_load_and_save_state_cb;
|
task->callback = content_load_and_save_state_cb;
|
||||||
task->title = strdup(msg_hash_to_str(MSG_LOADING_STATE));
|
task->title = strdup(msg_hash_to_str(MSG_LOADING_STATE));
|
||||||
|
|
||||||
task_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
|
task_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (data)
|
||||||
|
free(data);
|
||||||
|
if (task)
|
||||||
|
free(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1141,11 +1153,11 @@ bool content_save_state(const char *path, bool save_to_disk)
|
|||||||
**/
|
**/
|
||||||
bool content_load_state(const char *path, bool load_to_backup_buffer, bool autoload)
|
bool content_load_state(const char *path, bool load_to_backup_buffer, bool autoload)
|
||||||
{
|
{
|
||||||
retro_task_t *task = (retro_task_t*)calloc(1, sizeof(*task));
|
retro_task_t *task = (retro_task_t*)calloc(1, sizeof(*task));
|
||||||
save_task_state_t *state = (save_task_state_t*)calloc(1, sizeof(*state));
|
save_task_state_t *state = (save_task_state_t*)calloc(1, sizeof(*state));
|
||||||
|
|
||||||
if (!task || !state)
|
if (!task || !state)
|
||||||
return false;
|
goto error;
|
||||||
|
|
||||||
strlcpy(state->path, path, sizeof(state->path));
|
strlcpy(state->path, path, sizeof(state->path));
|
||||||
state->load_to_backup_buffer = load_to_backup_buffer;
|
state->load_to_backup_buffer = load_to_backup_buffer;
|
||||||
@ -1160,6 +1172,14 @@ bool content_load_state(const char *path, bool load_to_backup_buffer, bool autol
|
|||||||
task_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
|
task_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (state)
|
||||||
|
free(state);
|
||||||
|
if (task)
|
||||||
|
free(task);
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool content_rename_state(const char *origin, const char *dest)
|
bool content_rename_state(const char *origin, const char *dest)
|
||||||
|
@ -192,7 +192,11 @@ static bool screenshot_dump(
|
|||||||
#elif defined(HAVE_RPNG)
|
#elif defined(HAVE_RPNG)
|
||||||
state->out_buffer = (uint8_t*)malloc(width * height * 3);
|
state->out_buffer = (uint8_t*)malloc(width * height * 3);
|
||||||
if (!state->out_buffer)
|
if (!state->out_buffer)
|
||||||
|
{
|
||||||
|
if (task)
|
||||||
|
free(task);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
task->type = TASK_TYPE_BLOCKING;
|
task->type = TASK_TYPE_BLOCKING;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user