1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-06-12 17:14:46 +02:00

CommandAdd(): require flags to be non-zero and fix a minor memleak on-boot

This commit is contained in:
Bram Matthys
2015-07-15 10:20:07 +02:00
parent 8ef62b9f34
commit ceb04cc3eb
+22 -6
View File
@@ -39,8 +39,10 @@ int CommandExists(char *name)
return 0;
}
Command *CommandAdd(Module *module, char *cmd, int (*func)(), unsigned char params, int flags) {
Command *CommandAdd(Module *module, char *cmd, int (*func)(), unsigned char params, int flags)
{
Command *command;
aCommand *c;
if (find_Command_simple(cmd))
{
@@ -48,17 +50,30 @@ Command *CommandAdd(Module *module, char *cmd, int (*func)(), unsigned char para
module->errorcode = MODERR_EXISTS;
return NULL;
}
command = MyMallocEx(sizeof(Command));
command->cmd = add_Command_backend(cmd,func,params, flags);
command->cmd->owner = module;
command->cmd->friend = NULL;
if (module) {
if (!flags)
{
config_error("CommandAdd(): Could not add command '%s': flags are 0", cmd);
if (module)
module->errorcode = MODERR_INVALID;
return NULL;
}
c = add_Command_backend(cmd, func, params, flags);
if (module)
{
ModuleObject *cmdobj = (ModuleObject *)MyMallocEx(sizeof(ModuleObject));
command = MyMallocEx(sizeof(Command));
command->cmd = c;
command->cmd->owner = module;
command->cmd->friend = NULL;
cmdobj->object.command = command;
cmdobj->type = MOBJ_COMMAND;
AddListItem(cmdobj, module->objects);
module->errorcode = MODERR_NOERROR;
}
if (flags & M_ANNOUNCE)
{
char *tmp;
@@ -81,6 +96,7 @@ Command *CommandAdd(Module *module, char *cmd, int (*func)(), unsigned char para
IsupportAdd(NULL, "CMDS", tmp);
cmdstr = tmp;
}
return command;
}