Fix issues pointed out by static code analysis

This commit is contained in:
twinaphex 2020-06-29 19:15:07 +02:00
parent 8356fc90b6
commit fded8ab357

View File

@ -428,16 +428,26 @@ static void input_autoconfigure_disconnect_handler(retro_task_t *task)
bool input_autoconfigure_disconnect(unsigned i, const char *ident)
{
char msg[255];
retro_task_t *task = task_init();
autoconfig_disconnect_t *state = (autoconfig_disconnect_t*)malloc(sizeof(*state));
autoconfig_disconnect_t
*state = NULL;
retro_task_t
*task = task_init();
if (!state || !task)
goto error;
if (!task)
return false;
msg[0] = '\0';
state = (autoconfig_disconnect_t*)
malloc(sizeof(*state));
state->msg = NULL;
state->idx = i;
if (!state)
{
free(task);
return false;
}
state->idx = i;
state->msg = NULL;
msg[0] = '\0';
snprintf(msg, sizeof(msg), "%s #%u (%s).",
msg_hash_to_str(MSG_DEVICE_DISCONNECTED_FROM_PORT),
@ -456,18 +466,6 @@ bool input_autoconfigure_disconnect(unsigned i, const char *ident)
task_queue_push(task);
return true;
error:
if (state)
{
if (!string_is_empty(state->msg))
free(state->msg);
free(state);
}
if (task)
free(task);
return false;
}
void input_autoconfigure_reset(void)
@ -507,33 +505,44 @@ void input_autoconfigure_connect(
unsigned pid)
{
unsigned i;
retro_task_t *task = task_init();
autoconfig_params_t *state = (autoconfig_params_t*)malloc(sizeof(*state));
settings_t *settings = config_get_ptr();
const char *dir_autoconf = settings ? settings->paths.directory_autoconfig : NULL;
bool autodetect_enable = settings ? settings->bools.input_autodetect_enable : false;
settings_t *settings = config_get_ptr();
const char *dir_autoconf =
settings ? settings->paths.directory_autoconfig : NULL;
bool autodetect_enable = settings
? settings->bools.input_autodetect_enable : false;
autoconfig_params_t *state = NULL;
retro_task_t *task = NULL;
if (!task || !state || !autodetect_enable)
if (!autodetect_enable)
goto error;
task = task_init();
if (!task)
goto error;
state = (autoconfig_params_t*)
malloc(sizeof(*state));
if (!state)
{
if (state)
{
input_autoconfigure_params_free(state);
free(state);
}
if (task)
free(task);
input_config_set_device_name(idx, name);
return;
free(task);
goto error;
}
state->vid = 0;
state->pid = 0;
state->idx = 0;
state->max_users = 0;
state->name = NULL;
state->autoconfig_directory = NULL;
state->show_hidden_files = false;
state->vid = vid;
state->pid = pid;
state->idx = idx;
state->max_users = *(
input_driver_get_uint(INPUT_ACTION_MAX_USERS));
state->name = NULL;
state->autoconfig_directory = NULL;
if (!string_is_empty(name))
state->name = strdup(name);
@ -573,4 +582,9 @@ void input_autoconfigure_connect(
task->handler = input_autoconfigure_connect_handler;
task_queue_push(task);
return;
error:
input_config_set_device_name(idx, name);
}