]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Allow Timers to delete themselves in Tick()
authorAttila Molnar <attilamolnar@hush.com>
Thu, 30 Jan 2014 20:44:51 +0000 (21:44 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Thu, 30 Jan 2014 20:44:51 +0000 (21:44 +0100)
include/modules/dns.h
include/timer.h
src/inspsocket.cpp
src/modules/extra/m_pgsql.cpp
src/timer.cpp

index 905e52a3422eb66a61cc14ef51d7a6f9143480dd..7f863fcca3cdaf1a3bdda06b932926d800dd1379 100644 (file)
@@ -185,6 +185,7 @@ namespace DNS
                        Query rr(*this);
                        rr.error = ERROR_TIMEDOUT;
                        this->OnError(&rr);
+                       delete this;
                        return false;
                }
        };
index 2887e2b52f1a473af4167a3f7e32d4a262480d28..503fa82a2f460c1aa8c8bd705d206861608f9cd1 100644 (file)
@@ -87,6 +87,8 @@ class CoreExport Timer
        /** Called when the timer ticks.
         * You should override this method with some useful code to
         * handle the tick event.
+        * @param TIME The current time.
+        * @return True if the Timer object is still valid, false if it was destructed.
         */
        virtual bool Tick(time_t TIME) = 0;
 
index 798cde9b01dd3ad2c10bb9a94657cacb3a78e1ce..46f5bd3b217652e28d1a8f39d0510ec542960f3d 100644 (file)
@@ -440,7 +440,10 @@ bool SocketTimeout::Tick(time_t)
        ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "SocketTimeout::Tick");
 
        if (ServerInstance->SE->GetRef(this->sfd) != this->sock)
+       {
+               delete this;
                return false;
+       }
 
        if (this->sock->state == I_CONNECTING)
        {
@@ -456,6 +459,7 @@ bool SocketTimeout::Tick(time_t)
        }
 
        this->sock->Timeout = NULL;
+       delete this;
        return false;
 }
 
index 1ed5be6f0dfbc776e9be72ebb740e7a2f5e1916d..b3b7d43dfd45444e46fa5001d54413e4ccdf2bfa 100644 (file)
@@ -593,6 +593,7 @@ bool ReconnectTimer::Tick(time_t time)
 {
        mod->retimer = NULL;
        mod->ReadConf();
+       delete this;
        return false;
 }
 
index f541c7eb17f69ab2a96b395c6271a65bffb8519d..b897056e68919bdc846713107be09c3a758c69cc 100644 (file)
@@ -47,8 +47,9 @@ void TimerManager::TickTimers(time_t TIME)
                Timers.erase(i++);
 
                if (!t->Tick(TIME))
-                       delete t;
-               else if (t->GetRepeat())
+                       continue;
+
+               if (t->GetRepeat())
                {
                        t->SetTrigger(TIME + t->GetInterval());
                        AddTimer(t);