diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-12-07 19:16:46 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-12-07 19:16:46 +0000 |
commit | 49b693beb75b8292c5b378f46d2b357ebb2fdc8c (patch) | |
tree | 48509c73e73bcff5f510bc0ade4e2d5306dc8925 | |
parent | 275f58a955407eda93c451273bee48e1637e3b4a (diff) |
Ugly ugly craq in here in the cleanup stuff. Can be done nicer with a template, like this
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10862 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | src/inspircd.cpp | 120 |
1 files changed, 26 insertions, 94 deletions
diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 72b161b9b..ec18728b5 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -90,6 +90,15 @@ const char* ExitCodes[] = "CreateEvent failed" /* 19 */ }; +template<typename T> void DeleteZero(T* n) +{ + if (n != NULL) + { + delete n; + n = NULL; + } +} + void InspIRCd::Cleanup() { if (Config) @@ -132,102 +141,25 @@ void InspIRCd::Cleanup() 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; - } - + /* 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 */ + DeleteZero(this->Users); + DeleteZero(this->Modes); + DeleteZero(this->XLines); + DeleteZero(this->Parser); + DeleteZero(this->stats); + DeleteZero(this->Modules); + DeleteZero(this->BanCache); + DeleteZero(this->SNO); + DeleteZero(this->Config); + DeleteZero(this->Res); + DeleteZero(this->chanlist); + DeleteZero(this->PI); + DeleteZero(this->Threads); + DeleteZero(this->Timers); /* Close logging */ this->Logs->CloseLogs(); - - if (this->Logs) - { - delete this->Logs; - this->Logs = 0; - } + DeleteZero(this->Logs); delete RehashFinishMutex; } |