From e2322b3feb0b70a5c5d74fff4a9ab2bd7c85bcac Mon Sep 17 00:00:00 2001
From: peavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7>
Date: Sun, 17 Dec 2006 01:14:18 +0000
Subject: Use safe iter for deleting while iterating

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6024 e03df62e-2008-0410-955e-edbf42e46eb7
---
 src/modules/m_svshold.cpp | 35 ++++++++++++-----------------------
 1 file changed, 12 insertions(+), 23 deletions(-)

(limited to 'src/modules/m_svshold.cpp')

diff --git a/src/modules/m_svshold.cpp b/src/modules/m_svshold.cpp
index 945125c75..8c81427e9 100644
--- a/src/modules/m_svshold.cpp
+++ b/src/modules/m_svshold.cpp
@@ -242,33 +242,22 @@ class ModuleSVSHold : public Module
 
 	void ExpireBans()
 	{
-		bool go_again = true;
-
-		while (go_again)
+		SVSHoldlist::iterator iter,safeiter;
+		for (iter = SVSHolds.begin(); iter != SVSHolds.end(); iter++)
 		{
-			go_again = false;
-	
-			for (SVSHoldlist::iterator iter = SVSHolds.begin(); iter != SVSHolds.end(); iter++)
+			/* 0 == permanent, don't mess with them! -- w00t */
+			if ((*iter)->length != 0)
 			{
-				/* 0 == permanent, don't mess with them! -- w00t */
-				if ((*iter)->length != 0)
+				if ((*iter)->set_on + (*iter)->length <= ServerInstance->Time())
 				{
-					if ((*iter)->set_on + (*iter)->length <= ServerInstance->Time())
-					{
-						ServerInstance->Log(DEBUG, "m_svshold.so: hold on %s expired, removing...", (*iter)->nickname.c_str());
-						ServerInstance->WriteOpers("*** %li second SVSHOLD on %s (%s) set %u seconds ago expired", (*iter)->length, (*iter)->nickname.c_str(), (*iter)->reason.c_str(), ServerInstance->Time() - (*iter)->set_on);
-						HoldMap.erase(assign((*iter)->nickname));
-
-						delete *iter;
-
-						SVSHolds.erase(iter);
-
-						go_again = true;
-					}
+					ServerInstance->Log(DEBUG, "m_svshold.so: hold on %s expired, removing...", (*iter)->nickname.c_str());
+					ServerInstance->WriteOpers("*** %li second SVSHOLD on %s (%s) set %u seconds ago expired", (*iter)->length, (*iter)->nickname.c_str(), (*iter)->reason.c_str(), ServerInstance->Time() - (*iter)->set_on);
+					HoldMap.erase(assign((*iter)->nickname));
+					delete *iter;
+					safeiter = iter;
+					--iter;
+					SVSHolds.erase(safeiter);
 				}
-	
-				if (go_again == true)
-					break;
 			}
 		}
 	}
-- 
cgit v1.2.3