From 37fd031da06761c8a050105b55d73a8ab499fb74 Mon Sep 17 00:00:00 2001 From: danieldg Date: Tue, 13 Oct 2009 21:34:29 +0000 Subject: Remove Command and ModeHandler objects in their destructors; fixes possible pointer leak if a module was not careful when triggering exceptions in its constructor git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11872 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/command_parse.cpp | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'src/command_parse.cpp') diff --git a/src/command_parse.cpp b/src/command_parse.cpp index c8ca7d59e..fe0aab3b9 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -11,8 +11,6 @@ * --------------------------------------------------- */ -/* $Core */ - #include "inspircd.h" #include "xline.h" #include "socketengine.h" @@ -396,24 +394,16 @@ bool CommandParser::ProcessCommand(User *user, std::string &cmd) } } -void CommandParser::RemoveCommands(Module* source) +void CommandParser::RemoveCommand(Command* x) { - Commandtable::iterator i,safei; - for (i = cmdlist.begin(); i != cmdlist.end();) - { - safei = i; - i++; - RemoveCommand(safei, source); - } + Commandtable::iterator n = cmdlist.find(x->command); + if (n != cmdlist.end() && n->second == x) + cmdlist.erase(n); } -void CommandParser::RemoveCommand(Commandtable::iterator safei, Module* source) +Command::~Command() { - Command* x = safei->second; - if (x->creator == source) - { - cmdlist.erase(safei); - } + ServerInstance->Parser->RemoveCommand(this); } bool CommandParser::ProcessBuffer(std::string &buffer,User *user) @@ -426,7 +416,7 @@ bool CommandParser::ProcessBuffer(std::string &buffer,User *user) return ProcessCommand(user,buffer); } -bool CommandParser::CreateCommand(Command *f) +bool CommandParser::AddCommand(Command *f) { /* create the command and push it onto the table */ if (cmdlist.find(f->command) == cmdlist.end()) -- cgit v1.2.3