From 5fd6471070ecf0f9a0074714c57211e922257014 Mon Sep 17 00:00:00 2001 From: danieldg Date: Wed, 30 Sep 2009 16:28:43 +0000 Subject: [PATCH] Detect, complain, and don't crash when objects are inserted into cull list twice git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11782 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/cull_list.h | 4 ++-- src/cull_list.cpp | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/include/cull_list.h b/include/cull_list.h index bd2fb45da..2b3ed1391 100644 --- a/include/cull_list.h +++ b/include/cull_list.h @@ -21,12 +21,12 @@ */ class CoreExport CullList { - std::set list; + std::vector 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) */ diff --git a/src/cull_list.cpp b/src/cull_list.cpp index c45dff46c..5715c3147 100644 --- a/src/cull_list.cpp +++ b/src/cull_list.cpp @@ -11,20 +11,27 @@ * --------------------------------------------------- */ -/* $Core */ - #include "inspircd.h" -#include "cull_list.h" +#include void CullList::Apply() { - std::vector todel(list.begin(), list.end()); - list.clear(); - for(std::vector::iterator i = todel.begin(); i != todel.end(); i++) + std::set 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); + } } } -- 2.39.2