]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Ugly ugly craq in here in the cleanup stuff. Can be done nicer with a template, like...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 7 Dec 2008 19:16:46 +0000 (19:16 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 7 Dec 2008 19:16:46 +0000 (19:16 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10862 e03df62e-2008-0410-955e-edbf42e46eb7

src/inspircd.cpp

index 72b161b9b7d2f4997dbe9a8eeb2bf763d187b619..ec18728b509962b6b5f0166047efb8779d4a7d5e 100644 (file)
@@ -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;
 }