Fix memory leaks when parsing user commands.
This commit is contained in:
parent
9377fb537a
commit
aec89fc125
|
@ -231,6 +231,7 @@ static int command_parse(struct command_base* cbase, struct hub_user* user, cons
|
||||||
{
|
{
|
||||||
char* prefix;
|
char* prefix;
|
||||||
int n;
|
int n;
|
||||||
|
int ret;
|
||||||
struct hub_command* cmd = hub_malloc_zero(sizeof(struct hub_command));
|
struct hub_command* cmd = hub_malloc_zero(sizeof(struct hub_command));
|
||||||
struct command_handle* handler = NULL;
|
struct command_handle* handler = NULL;
|
||||||
struct linked_list* tokens = NULL;
|
struct linked_list* tokens = NULL;
|
||||||
|
@ -244,9 +245,8 @@ static int command_parse(struct command_base* cbase, struct hub_user* user, cons
|
||||||
n = split_string(message, "\\s", tokens, 0);
|
n = split_string(message, "\\s", tokens, 0);
|
||||||
if (n <= 0)
|
if (n <= 0)
|
||||||
{
|
{
|
||||||
command_destroy(cmd);
|
ret = 0; // FIXME
|
||||||
// FIXME
|
goto command_parse_cleanup;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find a matching command handler
|
// Find a matching command handler
|
||||||
|
@ -258,14 +258,14 @@ static int command_parse(struct command_base* cbase, struct hub_user* user, cons
|
||||||
handler = command_handler_lookup(cbase, cmd->prefix);
|
handler = command_handler_lookup(cbase, cmd->prefix);
|
||||||
if (!handler)
|
if (!handler)
|
||||||
{
|
{
|
||||||
return command_not_found(cbase, user, prefix);
|
ret = command_not_found(cbase, user, prefix);
|
||||||
|
goto command_parse_cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
command_destroy(cmd);
|
ret = command_syntax_error(cbase, user);
|
||||||
command_syntax_error(cbase, user);
|
goto command_parse_cleanup;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the first token.
|
// Remove the first token.
|
||||||
|
@ -274,27 +274,30 @@ static int command_parse(struct command_base* cbase, struct hub_user* user, cons
|
||||||
|
|
||||||
// Parse arguments
|
// Parse arguments
|
||||||
cmd->args = command_extract_arguments(cbase, handler, tokens);
|
cmd->args = command_extract_arguments(cbase, handler, tokens);
|
||||||
list_clear(tokens, &hub_free);
|
|
||||||
list_destroy(tokens);
|
|
||||||
|
|
||||||
if (!cmd->args)
|
if (!cmd->args)
|
||||||
{
|
{
|
||||||
command_destroy(cmd);
|
ret = 0;
|
||||||
// FIXME
|
goto command_parse_cleanup;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command_is_available(handler, user))
|
if (command_is_available(handler, user))
|
||||||
{
|
{
|
||||||
handler->handler(cbase, user, handler, cmd);
|
handler->handler(cbase, user, handler, cmd);
|
||||||
command_destroy(cmd);
|
ret = 0;
|
||||||
return 0;
|
goto command_parse_cleanup;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
command_destroy(cmd);
|
ret = command_access_denied(cbase, user, prefix);
|
||||||
return command_access_denied(cbase, user, prefix);
|
goto command_parse_cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
command_parse_cleanup:
|
||||||
|
command_destroy(cmd);
|
||||||
|
list_clear(tokens, &hub_free);
|
||||||
|
list_destroy(tokens);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* command_get_syntax(struct command_handle* handler)
|
const char* command_get_syntax(struct command_handle* handler)
|
||||||
|
|
Loading…
Reference in New Issue