From 7181dc35ce0f2d2a2bf2d2bd0d36a690c1cc6b95 Mon Sep 17 00:00:00 2001 From: "Robin Burchell w00t@inspircd.org" Date: Sat, 8 Nov 2008 00:42:55 +0000 Subject: [PATCH] Catch ModuleException thrown from module constructors, and halt load if one is recieved. git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1582 5417fbe8-f217-4b02-8779-1006273d7864 --- src/modules.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/modules.c b/src/modules.c index 393dc38c5..2b411e4d5 100644 --- a/src/modules.c +++ b/src/modules.c @@ -365,6 +365,7 @@ Module::Module(const std::string &mname, const std::string &creator) this->hostHelp = NULL; this->helpHelp = NULL; this->type = THIRD; + this->handle = NULL; for (int i = 0; i < NUM_LANGS; i++) { @@ -391,8 +392,11 @@ Module::~Module() if (this->version) free(this->version); - if ((ano_modclose(this->handle)) != 0) - alog("%s", ano_moderr()); + if (this->handle) + { + if ((ano_modclose(this->handle)) != 0) + alog("%s", ano_moderr()); + } /* * No need to free our cmd/msg list, as they will always be empty by the module is destroyed @@ -666,16 +670,25 @@ int loadModule(const std::string &modname, User * u) mod_current_module_name = modname.c_str(); - /* Create module. - * XXX: we need to handle ModuleException throws here. - */ + /* Create module. */ std::string nick; if (u) nick = u->nick; else nick = ""; - Module *m = func(nick); + Module *m; + + try + { + m = func(nick); + } + catch (ModuleException &ex) + { + alog("Error while loading %s: %s", modname.c_str(), ex.GetReason()); + return MOD_STOP; + } + mod_current_module = m; mod_current_user = u; m->filename = sstrdup(buf);