From 4b6bdeccb537b6f8030172c37afa7dc324e26765 Mon Sep 17 00:00:00 2001 From: danieldg Date: Sun, 17 Jan 2010 16:00:14 +0000 Subject: Add Module::init() for correct exception handling during hook registration git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12278 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modmanager_static.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/modmanager_static.cpp') diff --git a/src/modmanager_static.cpp b/src/modmanager_static.cpp index 322703679..e267a2c90 100644 --- a/src/modmanager_static.cpp +++ b/src/modmanager_static.cpp @@ -64,15 +64,20 @@ bool ModuleManager::Load(const char* name) { if ((**i).name == name) { + Module* c = NULL; try { - Module* c = (*(**i).init)(); + c = (*(**i).init)(); Modules[name] = c; + c->init(); FOREACH_MOD(I_OnLoadModule,OnLoadModule(c)); return true; } catch (CoreException& modexcept) { + if (c) + DoSafeUnload(c); + delete c; ServerInstance->Logs->Log("MODULE", DEFAULT, "Unable to load " + (**i).name + ": " + modexcept.GetReason()); } } @@ -117,15 +122,20 @@ void ModuleManager::LoadAll() ModCount = 0; for(std::vector::iterator i = modlist->begin(); i != modlist->end(); ++i) { + Module* c = NULL; try { - Module* c = (*(**i).init)(); + c = (*(**i).init)(); c->ModuleSourceFile = (**i).name; Modules[(**i).name] = c; + c->init(); FOREACH_MOD(I_OnLoadModule,OnLoadModule(c)); } catch (CoreException& modexcept) { + if (c) + DoSafeUnload(c); + delete c; ServerInstance->Logs->Log("MODULE", DEFAULT, "Unable to load " + (**i).name + ": " + modexcept.GetReason()); } } -- cgit v1.2.3