From be10eab6ce68d4f06cc7b14bc2fca35e005ce6b5 Mon Sep 17 00:00:00 2001 From: danieldg Date: Mon, 19 Oct 2009 20:12:22 +0000 Subject: Maintain refcount of Module objects to complain about leaked pointers git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11925 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/base.cpp | 15 +++++++++++++++ src/modules.cpp | 8 ++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/base.cpp b/src/base.cpp index 389f3915a..c0bc40811 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -270,3 +270,18 @@ void StringExtItem::free(void* item) { delete static_cast(item); } + +ModuleException::ModuleException(const std::string &message, Module* who) + : CoreException(message, who ? who->ModuleSourceFile : "A Module") +{ +} + +ModuleRef::ModuleRef(Module* v) : value(v) +{ + if (value) inc(value); +} + +ModuleRef::~ModuleRef() +{ + if (value) dec(value); +} diff --git a/src/modules.cpp b/src/modules.cpp index 87d25ac42..856addbf5 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -51,12 +51,16 @@ void Event::Send() // These declarations define the behavours of the base class Module (which does nothing at all) -Module::Module() { } +Module::Module() : refcount(0) { } CullResult Module::cull() { return classbase::cull(); } -Module::~Module() { } +Module::~Module() +{ + if (refcount) + ServerInstance->Logs->Log("MODULE", DEFAULT, "References remain to destructed module " + ModuleSourceFile); +} ModResult Module::OnSendSnotice(char &snomask, std::string &type, const std::string &message) { return MOD_RES_PASSTHRU; } void Module::OnUserConnect(User*) { } -- cgit v1.2.3