]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/base.cpp
Fix null dereference caused by tracking dummy
[user/henk/code/inspircd.git] / src / base.cpp
index 1b01da70710ab1948ea5c25dd834474c1e39eab4..59196fec1d6242fb1ca1a3f6ffad4cacd915517f 100644 (file)
  * ---------------------------------------------------
  */
 
-/* $Core */
-
 #include "inspircd_config.h"
 #include "base.h"
 #include <time.h>
 #include "inspircd.h"
+#include <typeinfo>
 
 classbase::classbase()
 {
+       if (ServerInstance && ServerInstance->Logs)
+               ServerInstance->Logs->Log("CULLLIST", DEBUG, "classbase::+%s @%p",
+                       typeid(*this).name(), (void*)this);
 }
 
-bool classbase::cull()
+CullResult classbase::cull()
 {
-       return true;
+       if (ServerInstance && ServerInstance->Logs)
+               ServerInstance->Logs->Log("CULLLIST", DEBUG, "classbase::-%s @%p",
+                       typeid(*this).name(), (void*)this);
+       return CullResult();
 }
 
 classbase::~classbase()
 {
+       if (ServerInstance && ServerInstance->Logs)
+               ServerInstance->Logs->Log("CULLLIST", DEBUG, "classbase::~%s @%p",
+                       typeid(*this).name(), (void*)this);
 }
 
-refcountbase::refcountbase() : refcount(0)
+CullResult::CullResult()
 {
 }
 
-bool refcountbase::cull()
+refcountbase::refcountbase() : refcount(0)
 {
-       return (refcount == 0);
 }
 
 refcountbase::~refcountbase()
@@ -129,12 +136,32 @@ void Extensible::doUnhookExtensions(const std::vector<ExtensionItem*>& toRemove)
        }
 }
 
-Extensible::~Extensible()
+static struct DummyExtensionItem : LocalExtItem
+{
+       DummyExtensionItem() : LocalExtItem("", NULL) {}
+       void free(void*) {}
+} dummy;
+
+Extensible::Extensible()
+{
+       extensions[&dummy] = NULL;
+}
+
+CullResult Extensible::cull()
 {
        for(ExtensibleStore::iterator i = extensions.begin(); i != extensions.end(); ++i)
        {
-               i->first->free(i->second);      
+               i->first->free(i->second);
        }
+       extensions.clear();
+       return classbase::cull();
+}
+
+Extensible::~Extensible()
+{
+       if (!extensions.empty() && ServerInstance && ServerInstance->Logs)
+               ServerInstance->Logs->Log("CULLLIST", DEBUG,
+                       "Extensible destructor called without cull @%p", (void*)this);
 }
 
 LocalExtItem::LocalExtItem(const std::string& Key, Module* mod) : ExtensionItem(Key, mod)