diff options
author | Adam <Adam@anope.org> | 2013-12-19 21:34:21 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2013-12-19 21:34:21 -0500 |
commit | c0cd76a0a5be7bbbcf3e891357e5a8caa7ad8038 (patch) | |
tree | 96f6d3be5a37f6c4a2374d35d3fd6714ecb974fa | |
parent | ab6cd3b26caf127d1052e58e9f906d8ed5c3d986 (diff) |
Don't leak opers and opertypes on /os reload, fix not updating opertypes on non conf opers on rehash
-rw-r--r-- | include/config.h | 1 | ||||
-rw-r--r-- | include/opertype.h | 2 | ||||
-rw-r--r-- | modules/commands/os_oper.cpp | 2 | ||||
-rw-r--r-- | modules/extra/m_sql_oper.cpp | 2 | ||||
-rw-r--r-- | src/config.cpp | 46 | ||||
-rw-r--r-- | src/opertype.cpp | 2 |
6 files changed, 42 insertions, 13 deletions
diff --git a/include/config.h b/include/config.h index a86a4433a..1bc566c5c 100644 --- a/include/config.h +++ b/include/config.h @@ -129,6 +129,7 @@ namespace Configuration Anope::map<Anope::string> bots; Conf(); + ~Conf(); void LoadConf(File &file); diff --git a/include/opertype.h b/include/opertype.h index f40f4722a..fba6645ce 100644 --- a/include/opertype.h +++ b/include/opertype.h @@ -25,8 +25,6 @@ struct CoreExport Oper bool require_oper; Anope::string password; Anope::string certfp; - /* True if this operator is set in the config */ - bool config; /* Hosts allowed to use this operator block */ std::vector<Anope::string> hosts; Anope::string vhost; diff --git a/modules/commands/os_oper.cpp b/modules/commands/os_oper.cpp index e4eafe2df..759f48688 100644 --- a/modules/commands/os_oper.cpp +++ b/modules/commands/os_oper.cpp @@ -145,7 +145,7 @@ class CommandOSOper : public Command continue; source.Reply(_("%-8s %s"), nc->o->name.c_str(), nc->o->ot->GetName().c_str()); - if (nc->o->config) + if (std::find(Config->Opers.begin(), Config->Opers.end(), nc->o) != Config->Opers.end()) source.Reply(_(" This oper is configured in the configuration file.")); for (std::list<User *>::const_iterator uit = nc->users.begin(); uit != nc->users.end(); ++uit) { diff --git a/modules/extra/m_sql_oper.cpp b/modules/extra/m_sql_oper.cpp index 85e5d8f7d..68a6d9084 100644 --- a/modules/extra/m_sql_oper.cpp +++ b/modules/extra/m_sql_oper.cpp @@ -49,7 +49,7 @@ class SQLOperResult : public SQL::Interface BotInfo *OperServ = Config->GetClient("OperServ"); if (opertype.empty()) { - if (user->Account() && user->Account()->o && !user->Account()->o->config && dynamic_cast<SQLOper *>(user->Account()->o)) + if (user->Account() && user->Account()->o && dynamic_cast<SQLOper *>(user->Account()->o)) { delete user->Account()->o; user->Account()->o = NULL; diff --git a/src/config.cpp b/src/config.cpp index 0d43db81d..e99ab32b8 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -295,7 +295,6 @@ Conf::Conf() : Block("") Oper *o = new Oper(nname, ot); o->require_oper = require_oper; - o->config = true; o->password = password; o->certfp = certfp; spacesepstream(host).GetTokens(o->hosts); @@ -492,12 +491,15 @@ Conf::Conf() : Block("") /* Below here can't throw */ - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) - { - NickCore *nc = it->second; - if (nc->o && nc->o->config) - nc->o = NULL; - } + if (Config) + /* Clear existing conf opers */ + for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + { + NickCore *nc = it->second; + if (nc->o && std::find(Config->Opers.begin(), Config->Opers.end(), nc->o) != Config->Opers.end()) + nc->o = NULL; + } + /* Apply new opers */ for (unsigned i = 0; i < this->Opers.size(); ++i) { Oper *o = this->Opers[i]; @@ -556,18 +558,46 @@ Conf::Conf() : Block("") } #endif - /* Apply module chnages */ if (Config) { + /* Apply module chnages */ for (unsigned i = 0; i < Config->ModulesAutoLoad.size(); ++i) if (std::find(this->ModulesAutoLoad.begin(), this->ModulesAutoLoad.end(), Config->ModulesAutoLoad[i]) == this->ModulesAutoLoad.end()) ModuleManager::UnloadModule(ModuleManager::FindModule(Config->ModulesAutoLoad[i]), NULL); for (unsigned i = 0; i < this->ModulesAutoLoad.size(); ++i) if (std::find(Config->ModulesAutoLoad.begin(), Config->ModulesAutoLoad.end(), this->ModulesAutoLoad[i]) == Config->ModulesAutoLoad.end()) ModuleManager::LoadModule(this->ModulesAutoLoad[i], NULL); + + /* Apply opertype changes, as non-conf opers still point to the old oper types */ + for (unsigned i = Oper::opers.size(); i > 0; --i) + { + Oper *o = Oper::opers[i - 1]; + + /* Oper's type is in the old config, so update it */ + if (std::find(Config->MyOperTypes.begin(), Config->MyOperTypes.end(), o->ot) != Config->MyOperTypes.end()) + { + OperType *ot = o->ot; + o->ot = NULL; + + for (unsigned j = 0; j < MyOperTypes.size(); ++j) + if (ot->GetName() == MyOperTypes[j]->GetName()) + o->ot = MyOperTypes[j]; + + if (o->ot == NULL) + delete o; /* Oper block has lost type */ + } + } } } +Conf::~Conf() +{ + for (unsigned i = 0; i < MyOperTypes.size(); ++i) + delete MyOperTypes[i]; + for (unsigned i = 0; i < Opers.size(); ++i) + delete Opers[i]; +} + Block *Conf::GetModule(Module *m) { if (!m) diff --git a/src/opertype.cpp b/src/opertype.cpp index 153b735ab..38a1f2f50 100644 --- a/src/opertype.cpp +++ b/src/opertype.cpp @@ -14,7 +14,7 @@ std::vector<Oper *> Oper::opers; -Oper::Oper(const Anope::string &n, OperType *o) : name(n), ot(o), require_oper(false), config(false) +Oper::Oper(const Anope::string &n, OperType *o) : name(n), ot(o), require_oper(false) { opers.push_back(this); } |