]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Detect, complain, and don't crash when objects are inserted into cull list twice
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 30 Sep 2009 16:28:43 +0000 (16:28 +0000)
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 30 Sep 2009 16:28:43 +0000 (16:28 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11782 e03df62e-2008-0410-955e-edbf42e46eb7

include/cull_list.h
src/cull_list.cpp

index bd2fb45dae899f220f7ebb9fb1ff0d6585a5c4ed..2b3ed13915435fa25d9f18a0c44c4760906827b7 100644 (file)
  */
 class CoreExport CullList
 {
-       std::set<classbase*> list;
+       std::vector<classbase*> list;
 
  public:
        /** Adds an item to the cull list
         */
-       void AddItem(classbase* item) { list.insert(item); }
+       void AddItem(classbase* item) { list.push_back(item); }
 
        /** Applies the cull list (deletes the contents)
         */
index c45dff46c3d7b27d1fde53ec31c80991c6ad5970..5715c314766bef230682b141452caa5d719bbac4 100644 (file)
  * ---------------------------------------------------
  */
 
-/* $Core */
-
 #include "inspircd.h"
-#include "cull_list.h"
+#include <typeinfo>
 
 void CullList::Apply()
 {
-       std::vector<classbase*> todel(list.begin(), list.end());
-       list.clear();
-       for(std::vector<classbase*>::iterator i = todel.begin(); i != todel.end(); i++)
+       std::set<classbase*> gone;
+       for(unsigned int i=0; i < list.size(); i++)
        {
-               classbase* c = *i;
-               c->cull();
-               delete c;
+               classbase* c = list[i];
+               if (gone.insert(c).second)
+               {
+                       ServerInstance->Logs->Log("CULLLIST", DEBUG, "Deleting %s @%p", typeid(*c).name(),
+                               (void*)c);
+                       c->cull();
+                       delete c;
+               }
+               else
+               {
+                       ServerInstance->Logs->Log("CULLLIST",DEBUG, "WARNING: Object @%p culled twice!",
+                               (void*)c);
+               }
        }
 }