summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-13 21:34:29 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-13 21:34:29 +0000
commit37fd031da06761c8a050105b55d73a8ab499fb74 (patch)
tree6709b8882806cfe2a4dd20bdcd0aa5581344955e
parent99064f734b9b1513c1d3b3792d6ea8102aae26e1 (diff)
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
-rw-r--r--include/command_parse.h15
-rw-r--r--include/ctables.h6
-rw-r--r--include/inspircd.h6
-rw-r--r--include/mode.h3
-rw-r--r--src/command_parse.cpp24
-rw-r--r--src/mode.cpp17
-rw-r--r--src/modules.cpp28
7 files changed, 18 insertions, 81 deletions
diff --git a/include/command_parse.h b/include/command_parse.h
index 10dbef58d..35f5a7b0e 100644
--- a/include/command_parse.h
+++ b/include/command_parse.h
@@ -43,10 +43,6 @@ class CoreExport CommandParser : public classbase
*/
bool ProcessCommand(User *user, std::string &cmd);
- /** Removes a command if the sources match. Used as a helper for
- * safe hash_map delete while iter in RemoveCommands(const char* source).
- */
- void RemoveCommand(nspace::hash_map<std::string,Command*>::iterator safei, Module* source);
public:
@@ -145,16 +141,15 @@ class CoreExport CommandParser : public classbase
*/
void DoLines(User* current, bool one_only = false);
- /** Remove all commands relating to module 'source'.
- * @param source A module which has introduced new commands
- */
- void RemoveCommands(Module* source);
-
/** Add a new command to the commands hash
* @param f The new Command to add to the list
* @return True if the command was added
*/
- bool CreateCommand(Command *f);
+ bool AddCommand(Command *f);
+
+ /** Removes a command.
+ */
+ void RemoveCommand(Command* x);
/** Translate nicknames in a string into UIDs, based on the TranslationType given.
* @param to The translation type to use for the process.
diff --git a/include/ctables.h b/include/ctables.h
index c0c094e6f..0cf4c50d2 100644
--- a/include/ctables.h
+++ b/include/ctables.h
@@ -90,7 +90,7 @@ class CoreExport Command : public Extensible
public:
/** Command name
*/
- std::string command;
+ const std::string command;
/** Creator module - never NULL */
Module* const creator;
@@ -211,9 +211,7 @@ class CoreExport Command : public Extensible
return works_before_reg;
}
- virtual ~Command()
- {
- }
+ virtual ~Command();
};
/** A hash of commands used by the core
diff --git a/include/inspircd.h b/include/inspircd.h
index 182d33c9c..700624892 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -727,12 +727,6 @@ class CoreExport InspIRCd : public classbase
*/
void RehashServer();
- /** Return the channel whos index number matches that provided
- * @param The index number of the channel to fetch
- * @return A channel record, or NUll if index < 0 or index >= InspIRCd::ChannelCount()
- */
- Channel* GetChannelIndex(long index);
-
/** Dump text to a user target, splitting it appropriately to fit
* @param User the user to dump the text to
* @param LinePrefix text to prefix each complete line with
diff --git a/include/mode.h b/include/mode.h
index beb493810..a9b0da656 100644
--- a/include/mode.h
+++ b/include/mode.h
@@ -510,9 +510,6 @@ class CoreExport ModeParser : public classbase
*/
bool DelMode(ModeHandler* mh);
- /** Delete all modes and mode watchers associated with a given module
- */
- void RemoveModes(Module* mod);
/** Add a mode watcher.
* A mode watcher is triggered before and after a mode handler is
* triggered. See the documentation of class ModeWatcher for more
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())
diff --git a/src/mode.cpp b/src/mode.cpp
index c37407223..1ac2b9e64 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -57,6 +57,7 @@ ModeHandler::ModeHandler(Module* Creator, const std::string& Name, char modelett
ModeHandler::~ModeHandler()
{
+ ServerInstance->Modes->DelMode(this);
}
bool ModeHandler::IsListMode()
@@ -690,22 +691,6 @@ bool ModeParser::DelMode(ModeHandler* mh)
return true;
}
-void ModeParser::RemoveModes(Module* mod)
-{
- for(int i=0; i < 256; i++)
- {
- ModeHandler* mh = modehandlers[i];
- if (mh && mh->creator == mod)
- DelMode(mh);
- for(unsigned int j=0; j < modewatchers[i].size(); j++)
- {
- ModeWatcher* mw = modewatchers[i][j];
- if (mw && mw->creator == mod)
- DelModeWatcher(mw);
- }
- }
-}
-
ModeHandler* ModeParser::FindMode(unsigned const char modeletter, ModeType mt)
{
unsigned char mask = 0;
diff --git a/src/modules.cpp b/src/modules.cpp
index 1c4f47103..71363ae9d 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -474,9 +474,6 @@ bool ModuleManager::Unload(const char* filename)
this->DetachAll(modfind->second);
- ServerInstance->Parser->RemoveCommands(modfind->second);
- ServerInstance->Modes->RemoveModes(modfind->second);
-
ServerInstance->GlobalCulls.AddItem(modfind->second);
Modules.erase(modfind);
@@ -495,7 +492,7 @@ bool ModuleManager::Unload(const char* filename)
void ModuleManager::LoadAll()
{
char configToken[MAXBUF];
- ModCount = -1;
+ ModCount = 0;
printf("\nLoading core commands");
fflush(stdout);
@@ -670,24 +667,6 @@ const std::string& ModuleManager::GetModuleName(Module* m)
return nothing;
}
-/* This is ugly, yes, but hash_map's arent designed to be
- * addressed in this manner, and this is a bit of a kludge.
- * Luckily its a specialist function and rarely used by
- * many modules (in fact, it was specially created to make
- * m_safelist possible, initially).
- */
-
-Channel* InspIRCd::GetChannelIndex(long index)
-{
- int target = 0;
- for (chan_hash::iterator n = this->chanlist->begin(); n != this->chanlist->end(); n++, target++)
- {
- if (index == target)
- return n->second;
- }
- return NULL;
-}
-
CmdResult InspIRCd::CallCommandHandler(const std::string &commandname, const std::vector<std::string>& parameters, User* user)
{
return this->Parser->CallHandler(commandname, parameters, user);
@@ -700,10 +679,9 @@ bool InspIRCd::IsValidModuleCommand(const std::string &commandname, int pcnt, Us
void InspIRCd::AddCommand(Command *f)
{
- if (!this->Parser->CreateCommand(f))
+ if (!this->Parser->AddCommand(f))
{
- ModuleException err("Command "+std::string(f->command)+" already exists.");
- throw (err);
+ throw ModuleException("Command "+std::string(f->command)+" already exists.");
}
}