Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove some IMHO dangerous functions

Instead, these functions are now inlined into their only caller. This should
make the user and network destruction a little saner. At least I hope so...

Signed-off-by: Uli Schlachter <psychon@znc.in>
  • Loading branch information...
commit 9c9e40a3d78b979868e5e37b93da0bdde3d42776 1 parent bd3e6d3
@psychon psychon authored
Showing with 40 additions and 63 deletions.
  1. +22 −26 IRCNetwork.cpp
  2. +0 −2  IRCNetwork.h
  3. +18 −26 User.cpp
  4. +0 −4 User.h
  5. +0 −5 znc.cpp
View
48 IRCNetwork.cpp
@@ -134,15 +134,33 @@ CIRCNetwork::CIRCNetwork(CUser *pUser, const CIRCNetwork *pNetwork, bool bCloneC
}
CIRCNetwork::~CIRCNetwork() {
- DelClients();
+ // Delete modules (this unloads all modules)
+ delete m_pModules;
+ m_pModules = NULL;
+
+ // Delete clients
+ for (vector<CClient*>::const_iterator it = m_vClients.begin(); it != m_vClients.end(); ++it) {
+ CZNC::Get().GetManager().DelSockByAddr(*it);
+ }
+ m_vClients.clear();
+
+ // Delete servers
DelServers();
- DelModules();
+
+ // Delete Channels
+ for (vector<CChan*>::const_iterator it = m_vChans.begin(); it != m_vChans.end(); ++it) {
+ delete *it;
+ }
+ m_vChans.clear();
SetUser(NULL);
+}
- for (unsigned int b = 0; b < m_vChans.size(); b++) {
- delete m_vChans[b];
+void CIRCNetwork::DelServers() {
+ for (vector<CServer*>::const_iterator it = m_vServers.begin(); it != m_vServers.end(); ++it) {
+ delete *it;
}
+ m_vServers.clear();
}
CString CIRCNetwork::GetNetworkPath() {
@@ -155,28 +173,6 @@ CString CIRCNetwork::GetNetworkPath() {
return sNetworkPath;
}
-void CIRCNetwork::DelClients() {
- for (unsigned int c = 0; c < m_vClients.size(); c++) {
- CClient* pClient = m_vClients[c];
- CZNC::Get().GetManager().DelSockByAddr(pClient);
- }
-
- m_vClients.clear();
-}
-
-void CIRCNetwork::DelServers() {
- for (unsigned int a = 0; a < m_vServers.size(); a++) {
- delete m_vServers[a];
- }
-
- m_vServers.clear();
-}
-
-void CIRCNetwork::DelModules() {
- delete m_pModules;
- m_pModules = NULL;
-}
-
bool CIRCNetwork::ParseConfig(CConfig *pConfig, CString& sError, bool bUpgrade) {
VCString vsList;
VCString::const_iterator vit;
View
2  IRCNetwork.h
@@ -35,7 +35,6 @@ class CIRCNetwork {
CString GetNetworkPath();
- void DelClients();
void DelServers();
bool ParseConfig(CConfig *pConfig, CString& sError, bool bUpgrade = false);
@@ -56,7 +55,6 @@ class CIRCNetwork {
bool SetName(const CString& sName);
// Modules
- void DelModules();
CModules& GetModules() { return *m_pModules; }
const CModules& GetModules() const { return *m_pModules; }
// !Modules
View
44 User.cpp
@@ -88,13 +88,28 @@ CUser::CUser(const CString& sUserName)
}
CUser::~CUser() {
- DelNetworks();
+ // Delete modules (unloads all modules!)
+ delete m_pModules;
+ m_pModules = NULL;
- DelClients();
+ // Delete networks
+ for (unsigned int c = 0; c < m_vIRCNetworks.size(); c++) {
+ CIRCNetwork* pNetwork = m_vIRCNetworks[c];
+ delete pNetwork;
+ }
+ m_vIRCNetworks.clear();
- DelModules();
+ // Delete clients
+ for (unsigned int c = 0; c < m_vClients.size(); c++) {
+ CClient* pClient = m_vClients[c];
+ CZNC::Get().GetManager().DelSockByAddr(pClient);
+ }
+ m_vClients.clear();
CZNC::Get().GetManager().DelCronByAddr(m_pUserTimer);
+
+ CZNC::Get().AddBytesRead(BytesRead());
+ CZNC::Get().AddBytesWritten(BytesWritten());
}
template<class T>
@@ -395,11 +410,6 @@ bool CUser::ParseConfig(CConfig* pConfig, CString& sError) {
return true;
}
-void CUser::DelModules() {
- delete m_pModules;
- m_pModules = NULL;
-}
-
bool CUser::UpdateModule(const CString &sModule) {
const map<CString,CUser*>& Users = CZNC::Get().GetUserMap();
map<CString,CUser*>::const_iterator it;
@@ -427,24 +437,6 @@ bool CUser::UpdateModule(const CString &sModule) {
return !error;
}
-void CUser::DelNetworks() {
- for (unsigned int c = 0; c < m_vIRCNetworks.size(); c++) {
- CIRCNetwork* pNetwork = m_vIRCNetworks[c];
- delete pNetwork;
- }
-
- m_vIRCNetworks.clear();
-}
-
-void CUser::DelClients() {
- for (unsigned int c = 0; c < m_vClients.size(); c++) {
- CClient* pClient = m_vClients[c];
- CZNC::Get().GetManager().DelSockByAddr(pClient);
- }
-
- m_vClients.clear();
-}
-
CIRCNetwork* CUser::AddNetwork(const CString &sNetwork) {
if (!CIRCNetwork::IsValidNetwork(sNetwork) || FindNetwork(sNetwork)) {
return NULL;
View
4 User.h
@@ -57,10 +57,6 @@ class CUser {
static bool IsValidUserName(const CString& sUserName);
static CString MakeCleanUserName(const CString& sUserName);
- void DelNetworks();
- void DelClients();
- void DelModules();
-
// Unloads a module on all users who have it loaded and loads it again.
static bool UpdateModule(const CString &sModule);
View
5 znc.cpp
@@ -180,12 +180,7 @@ bool CZNC::HandleUserDeletion()
}
}
- pUser->DelNetworks();
- pUser->DelClients();
- pUser->DelModules();
CWebSock::FinishUserSessions(*pUser);
- AddBytesRead(pUser->BytesRead());
- AddBytesWritten(pUser->BytesWritten());
delete pUser;
}
Please sign in to comment.
Something went wrong with that request. Please try again.