Fix 17 new memory leaks catched by Coverity

This commit is contained in:
twinaphex 2016-10-04 11:02:01 +02:00
parent d3933f04c6
commit f06ea9ba70
2 changed files with 51 additions and 27 deletions

View File

@ -618,11 +618,7 @@ static void task_push_undo_save_state(const char *path, void *data, size_t size)
save_task_state_t *state = (save_task_state_t*)calloc(1, sizeof(*state));
if (!task || !state)
{
if (data)
free(data);
return;
}
goto error;
strlcpy(state->path, path, sizeof(state->path));
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_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));
if (!task || !state)
{
if (data)
free(data);
return;
}
goto error;
strlcpy(state->path, path, sizeof(state->path));
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_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
return;
error:
if (data)
free(data);
if (task)
free(task);
}
/**
@ -1018,11 +1026,7 @@ static void task_push_load_and_save_state(const char *path, void *data, size_t s
save_task_state_t *state = (save_task_state_t*)calloc(1, sizeof(*state));
if (!task || !state)
{
if (data)
free(data);
return;
}
goto error;
strlcpy(state->path, path, sizeof(state->path));
state->load_to_backup_buffer = load_to_backup_buffer;
@ -1036,6 +1040,14 @@ static void task_push_load_and_save_state(const char *path, void *data, size_t s
task->title = strdup(msg_hash_to_str(MSG_LOADING_STATE));
task_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
return;
error:
if (data)
free(data);
if (task)
free(task);
}
/**
@ -1145,7 +1157,7 @@ bool content_load_state(const char *path, bool load_to_backup_buffer, bool autol
save_task_state_t *state = (save_task_state_t*)calloc(1, sizeof(*state));
if (!task || !state)
return false;
goto error;
strlcpy(state->path, path, sizeof(state->path));
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);
return true;
error:
if (state)
free(state);
if (task)
free(task);
return false;
}
bool content_rename_state(const char *origin, const char *dest)

View File

@ -192,7 +192,11 @@ static bool screenshot_dump(
#elif defined(HAVE_RPNG)
state->out_buffer = (uint8_t*)malloc(width * height * 3);
if (!state->out_buffer)
{
if (task)
free(task);
return false;
}
#endif
task->type = TASK_TYPE_BLOCKING;