diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-02 00:43:04 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-02 00:43:04 +0000 |
commit | 2630a87bb13b089e6d0fdcff4bcd0f3a9612e52f (patch) | |
tree | 8a780298dbc1311024047a2587fddcd0beafd2ca /src/modules/m_cgiirc.cpp | |
parent | de87dec941cbf1eb6950a508876d654e2a3b63e4 (diff) |
Change allocation of commands/modes
API change: Commands passed to AddCommand are no longer deleted automatically
This removes lots of needless heap allocation and fixes a few memory leaks by
allocating commands and modes as part of the Module rather than creating them
separately in the module constructor.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11592 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/m_cgiirc.cpp')
-rw-r--r-- | src/modules/m_cgiirc.cpp | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp index 1467d0f68..8b7a77941 100644 --- a/src/modules/m_cgiirc.cpp +++ b/src/modules/m_cgiirc.cpp @@ -53,9 +53,9 @@ typedef std::vector<CGIhost> CGIHostlist; */ class CommandWebirc : public Command { - CGIHostlist Hosts; - bool notify; + bool notify; public: + CGIHostlist Hosts; CommandWebirc(InspIRCd* Instance, bool bnotify) : Command(Instance, "WEBIRC", 0, 4, true), notify(bnotify) { this->source = "m_cgiirc.so"; @@ -86,11 +86,6 @@ class CommandWebirc : public Command ServerInstance->SNO->WriteGlobalSno('a', "Connecting user %s tried to use WEBIRC, but didn't match any configured webirc blocks.", user->GetFullRealHost().c_str()); return CMD_FAILURE; } - - void SetHosts(CGIHostlist &phosts) - { - this->Hosts = phosts; - } }; @@ -140,15 +135,13 @@ class CGIResolver : public Resolver class ModuleCgiIRC : public Module { - CommandWebirc* mycommand; + CommandWebirc cmd; bool NotifyOpers; - CGIHostlist Hosts; public: - ModuleCgiIRC(InspIRCd* Me) : Module(Me) + ModuleCgiIRC(InspIRCd* Me) : Module(Me), cmd(Me, NotifyOpers) { - mycommand = new CommandWebirc(Me, NotifyOpers); OnRehash(NULL); - ServerInstance->AddCommand(mycommand); + ServerInstance->AddCommand(&cmd); Implementation eventlist[] = { I_OnRehash, I_OnUserRegister, I_OnCleanup, I_OnSyncUserMetaData, I_OnDecodeMetaData, I_OnUserDisconnect, I_OnUserConnect }; ServerInstance->Modules->Attach(eventlist, this, 7); @@ -163,7 +156,7 @@ public: virtual void OnRehash(User* user) { ConfigReader Conf(ServerInstance); - Hosts.clear(); + cmd.Hosts.clear(); NotifyOpers = Conf.ReadFlag("cgiirc", "opernotice", 0); // If we send an oper notice when a CGI:IRC has their host changed. @@ -198,7 +191,7 @@ public: if (cgitype == INVALID) cgitype = PASS; - Hosts.push_back(CGIhost(hostmask,cgitype, password.length() ? password : "" )); + cmd.Hosts.push_back(CGIhost(hostmask,cgitype, password.length() ? password : "" )); } } else @@ -207,8 +200,6 @@ public: continue; } } - - mycommand->SetHosts(Hosts); } virtual void OnCleanup(int target_type, void* item) @@ -267,7 +258,7 @@ public: virtual int OnUserRegister(User* user) { - for(CGIHostlist::iterator iter = Hosts.begin(); iter != Hosts.end(); iter++) + for(CGIHostlist::iterator iter = cmd.Hosts.begin(); iter != cmd.Hosts.end(); iter++) { if(InspIRCd::Match(user->host, iter->hostmask, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(user->GetIPString(), iter->hostmask, ascii_case_insensitive_map)) { |