summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-04-21 16:59:23 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-04-21 16:59:23 +0000
commit98659aa0dcac7636627846555ef7d5f807152b7e (patch)
tree4726b3771ad6874862f2ff7b503264eed617f8d4 /src
parentf21617328a8a576c8ada619f2934ac31f0dec717 (diff)
Merge in large patchset from GreenReaper, useful fixes for freeing a ton of different things on shutdown for tidyness, and a few stack corruption fixes in the mode handler
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9565 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/commands/cmd_die.cpp8
-rw-r--r--src/configreader.cpp5
-rw-r--r--src/dns.cpp1
-rw-r--r--src/inspircd.cpp125
-rw-r--r--src/mode.cpp3
-rw-r--r--src/modes/cmode_l.cpp2
-rw-r--r--src/modules.cpp4
-rw-r--r--src/server.cpp3
-rw-r--r--src/snomasks.cpp7
-rw-r--r--src/xline.cpp12
10 files changed, 150 insertions, 20 deletions
diff --git a/src/commands/cmd_die.cpp b/src/commands/cmd_die.cpp
index 761127dcb..2723ecca3 100644
--- a/src/commands/cmd_die.cpp
+++ b/src/commands/cmd_die.cpp
@@ -26,9 +26,11 @@ CmdResult CommandDie::Handle (const char* const* parameters, int pcnt, User *use
{
if (!ServerInstance->PassCompare(user, ServerInstance->Config->diepass, parameters[0], ServerInstance->Config->powerhash))
{
- std::string diebuf = std::string("*** DIE command from ") + user->nick + "!" + user->ident + "@" + user->dhost + ". Terminating in " + ConvToStr(ServerInstance->Config->DieDelay) + " seconds.";
- ServerInstance->Logs->Log("COMMAND",SPARSE, diebuf);
- ServerInstance->SendError(diebuf);
+ {
+ std::string diebuf = std::string("*** DIE command from ") + user->nick + "!" + user->ident + "@" + user->dhost + ". Terminating in " + ConvToStr(ServerInstance->Config->DieDelay) + " seconds.";
+ ServerInstance->Logs->Log("COMMAND",SPARSE, diebuf);
+ ServerInstance->SendError(diebuf);
+ }
if (ServerInstance->Config->DieDelay)
sleep(ServerInstance->Config->DieDelay);
diff --git a/src/configreader.cpp b/src/configreader.cpp
index 29dff39ca..e45a76b40 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -36,7 +36,7 @@ bool DoneELine(ServerConfig* conf, const char* tag);
ServerConfig::ServerConfig(InspIRCd* Instance) : ServerInstance(Instance)
{
this->ClearStack();
- *ServerName = *Network = *ServerDesc = *AdminName = '\0';
+ *sid = *ServerName = *Network = *ServerDesc = *AdminName = '\0';
*HideWhoisServer = *AdminEmail = *AdminNick = *diepass = *restartpass = *FixedQuit = *HideKillsServer = '\0';
*DefaultModes = *CustomVersion = *motd = *rules = *PrefixQuit = *DieValue = *DNSServer = '\0';
*UserStats = *ModPath = *MyExecutable = *DisabledCommands = *PID = *SuffixQuit = '\0';
@@ -1960,7 +1960,7 @@ bool ServerConfig::DirValid(const char* dirandfile)
{
#ifdef WINDOWS
return true;
-#endif
+#else
char work[1024];
char buffer[1024];
@@ -2011,6 +2011,7 @@ bool ServerConfig::DirValid(const char* dirandfile)
{
return false;
}
+#endif
}
std::string ServerConfig::GetFullProgDir()
diff --git a/src/dns.cpp b/src/dns.cpp
index 2e393de53..ad59a98e4 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -934,7 +934,6 @@ DNS::~DNS()
ServerInstance->SE->Shutdown(this, 2);
ServerInstance->SE->Close(this);
ServerInstance->Timers->DelTimer(this->PruneTimer);
- delete this->PruneTimer;
}
CachedQuery* DNS::GetCache(const std::string &source)
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index d533a6e45..d09dff840 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -112,15 +112,109 @@ void InspIRCd::Cleanup()
this->Modules->Unload(k->c_str());
}
}
-
- /* Close logging */
- this->Logs->CloseLogs();
+ /* Remove core commands */
+ Parser->RemoveCommands("<core>");
/* Cleanup Server Names */
for(servernamelist::iterator itr = servernames.begin(); itr != servernames.end(); ++itr)
delete (*itr);
+ /* Delete objects dynamically allocated in constructor
+ * (destructor would be more appropriate, but we're likely exiting)
+ */
+
+ // Must be deleted before modes as it decrements modelines
+ if (this->Users)
+ {
+ delete this->Users;
+ this->Users = 0;
+ }
+
+ if (this->Modes)
+ {
+ delete this->Modes;
+ this->Modes = 0;
+ }
+
+ if (this->XLines)
+ {
+ delete this->XLines;
+ this->XLines = 0;
+ }
+ if (this->Parser)
+ {
+ delete this->Parser;
+ this->Parser = 0;
+
+ if (this->stats)
+ {
+ delete this->stats;
+ this->stats = 0;
+ }
+
+ if (this->Modules)
+ {
+ delete this->Modules;
+ this->Modules = 0;
+ }
+
+ if (this->BanCache)
+ delete this->BanCache;
+ this->BanCache = 0;
+ }
+
+ if (this->SNO)
+ {
+ delete this->SNO;
+ this->SNO = 0;
+ }
+
+ if (this->Config)
+ {
+ delete this->Config;
+ this->Config = 0;
+ }
+
+ if (this->Res)
+ {
+ delete this->Res;
+ this->Res = 0;
+ }
+
+ if (this->chanlist)
+ {
+ delete chanlist;
+ chanlist = 0;
+ }
+
+ if (this->PI)
+ {
+ delete this->PI;
+ this->PI = 0;
+ }
+
+ if (this->Threads)
+ {
+ delete this->Threads;
+ this->Threads = 0;
+ }
+
+ /* Needs to be deleted after Res, DNS has a timer */
+ if (this->Timers)
+ {
+ delete this->Timers;
+ this->Timers = 0;
+ }
+
+ /* Close logging */
+ this->Logs->CloseLogs();
+
+ if (this->Logs)
+ {
+ delete this->Logs;
+ this->Logs = 0;
+ }
}
void InspIRCd::Restart(const std::string &reason)
@@ -312,7 +406,11 @@ InspIRCd::InspIRCd(int argc, char** argv)
{
#ifdef WIN32
+ // Strict, frequent checking of memory on debug builds
_CrtSetDbgFlag ( _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
+
+ // Avoid erroneous frees on early exit
+ WindowsIPC = 0;
#endif
int found_ports = 0;
FailedPortList pl;
@@ -320,6 +418,24 @@ InspIRCd::InspIRCd(int argc, char** argv)
do_nolog = 0, do_root = 0, do_testsuite = 0; /* flag variables */
char c = 0;
+ // Initialize so that if we exit before proper initialization they're not deleted
+ this->Logs = 0;
+ this->Threads = 0;
+ this->PI = 0;
+ this->Users = 0;
+ this->chanlist = 0;
+ this->Config = 0;
+ this->SNO = 0;
+ this->BanCache = 0;
+ this->Modules = 0;
+ this->stats = 0;
+ this->Timers = 0;
+ this->Parser = 0;
+ this->XLines = 0;
+ this->Modes = 0;
+ this->Res = 0;
+
+
memset(&server, 0, sizeof(server));
memset(&client, 0, sizeof(client));
@@ -348,8 +464,6 @@ InspIRCd::InspIRCd(int argc, char** argv)
this->Users->uuidlist = new user_hash();
this->chanlist = new chan_hash();
- this->Res = NULL;
-
this->Config = new ServerConfig(this);
this->SNO = new SnomaskManager(this);
this->BanCache = new BanCacheManager(this);
@@ -530,6 +644,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
Config->sid[0] = (char)(sid / 100 + 48);
Config->sid[1] = (char)(((sid / 10) % 10) + 48);
Config->sid[2] = (char)(sid % 10 + 48);
+ Config->sid[3] = '\0';
}
/* set up fake client again this time with the correct uid */
diff --git a/src/mode.cpp b/src/mode.cpp
index e562a8551..e5efaffdf 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -1125,9 +1125,8 @@ ModeParser::ModeParser(InspIRCd* Instance) : ServerInstance(Instance)
NULL
};
- /* Clear mode list */
+ /* Clear mode handler list */
memset(modehandlers, 0, sizeof(modehandlers));
- memset(modewatchers, 0, sizeof(modewatchers));
/* Last parse string */
LastParse.clear();
diff --git a/src/modes/cmode_l.cpp b/src/modes/cmode_l.cpp
index 5c9db31df..4ed95bc2c 100644
--- a/src/modes/cmode_l.cpp
+++ b/src/modes/cmode_l.cpp
@@ -92,6 +92,4 @@ ModeAction ModeChannelLimit::OnModeChange(User*, User*, Channel* channel, std::s
return MODEACTION_ALLOW;
}
-
- return MODEACTION_DENY;
}
diff --git a/src/modules.cpp b/src/modules.cpp
index df6876b1a..617d5a0fa 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -602,14 +602,12 @@ bool ModuleManager::PublishInterface(const std::string &InterfaceName, Module* M
modulelist ml;
ml.push_back(Mod);
Interfaces[InterfaceName] = std::make_pair(0, ml);
- return true;
}
else
{
iter->second.second.push_back(Mod);
- return true;
}
- return false;
+ return true;
}
bool ModuleManager::UnpublishInterface(const std::string &InterfaceName, Module* Mod)
diff --git a/src/server.cpp b/src/server.cpp
index c713a028f..ae1d106b8 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -34,7 +34,8 @@ void InspIRCd::SignalHandler(int signal)
void InspIRCd::Exit(int status)
{
#ifdef WINDOWS
- delete WindowsIPC;
+ if (WindowsIPC)
+ delete WindowsIPC;
#endif
if (this)
{
diff --git a/src/snomasks.cpp b/src/snomasks.cpp
index de900623d..e6323b50c 100644
--- a/src/snomasks.cpp
+++ b/src/snomasks.cpp
@@ -24,7 +24,12 @@ SnomaskManager::SnomaskManager(InspIRCd* Instance) : ServerInstance(Instance)
}
SnomaskManager::~SnomaskManager()
-{
+{
+ for (std::map<char, Snomask *>::iterator i = SnoMasks.begin(); i != SnoMasks.end(); i++)
+ {
+ delete i->second;
+ }
+ SnoMasks.clear();
}
void SnomaskManager::FlushSnotices()
diff --git a/src/xline.cpp b/src/xline.cpp
index 47e122420..610af2e6c 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -391,6 +391,18 @@ XLineManager::~XLineManager()
delete KFact;
delete QFact;
delete ZFact;
+
+ // Delete all existing XLines
+ for (XLineContainer::iterator i = lookup_lines.begin(); i != lookup_lines.end(); i++)
+ {
+ for (XLineLookup::iterator j = i->second.begin(); j != i->second.end(); j++)
+ {
+ delete j->second;
+ }
+ i->second.clear();
+ }
+ lookup_lines.clear();
+
}
void XLine::Apply(User* u)