From 1929ce5ba994679aebcdc93dfdd35fc372d8af75 Mon Sep 17 00:00:00 2001 From: prozacx Date: Mon, 19 Sep 2005 02:19:17 +0000 Subject: [PATCH] Renamed CZNC::New() to CZNC::Get() and return a static reference instead of a pointer git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@504 726aef4b-f618-498e-8847-2d620e286838 --- main.cpp | 36 +++++++++++++----------------------- modules/webadmin.cpp | 2 +- znc.h | 6 +++--- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/main.cpp b/main.cpp index 980b340d..3e9451bb 100644 --- a/main.cpp +++ b/main.cpp @@ -43,7 +43,6 @@ void die(int sig) { } #endif /* _DEBUG */ - delete CZNC::New(); exit(sig); } @@ -104,9 +103,9 @@ int main(int argc, char** argv, char** envp) { sConfig = argv[optind]; if (bMakeConf) { - CZNC* pZNC = CZNC::New(); - pZNC->InitDirs(""); - if (pZNC->WriteNewConfig(sConfig)) { + CZNC& ZNC = CZNC::Get(); + ZNC.InitDirs(""); + if (ZNC.WriteNewConfig(sConfig)) { if (argc > 2) { char* args[3]; args[0] = argv[0]; @@ -128,15 +127,14 @@ int main(int argc, char** argv, char** envp) { #ifdef HAVE_LIBSSL if (bMakePem) { - CZNC* pZNC = CZNC::New(); - pZNC->InitDirs(""); - CString sPemFile = pZNC->GetPemLocation(); + CZNC& ZNC = CZNC::Get(); + ZNC.InitDirs(""); + CString sPemFile = ZNC.GetPemLocation(); CUtils::PrintAction("Writing Pem file [" + sPemFile + "]"); if (CFile::Exists(sPemFile)) { CUtils::PrintStatus(false, "File already exists"); - delete pZNC; return 1; } @@ -144,7 +142,6 @@ int main(int argc, char** argv, char** envp) { if (!f) { CUtils::PrintStatus(false, "Unable to open"); - delete pZNC; return 1 ; } @@ -153,7 +150,6 @@ int main(int argc, char** argv, char** envp) { CUtils::PrintStatus(true); - delete pZNC; return 0; } #endif /* HAVE_LIBSSL */ @@ -165,24 +161,21 @@ int main(int argc, char** argv, char** envp) { return 0; } - CZNC* pZNC = CZNC::New(); - pZNC->InitDirs(((argc) ? argv[0] : "")); + CZNC& ZNC = CZNC::Get(); + ZNC.InitDirs(((argc) ? argv[0] : "")); - if (!pZNC->ParseConfig(sConfig)) { + if (!ZNC.ParseConfig(sConfig)) { CUtils::PrintError("Unrecoverable config error."); - delete pZNC; return 1; } - if (!pZNC->GetListenPort()) { + if (!ZNC.GetListenPort()) { CUtils::PrintError("You must supply a ListenPort in your config."); - delete pZNC; return 1; } - if (!pZNC->OnBoot()) { + if (!ZNC.OnBoot()) { CUtils::PrintError("Exiting due to module boot errors."); - delete pZNC; return 1; } @@ -195,14 +188,13 @@ int main(int argc, char** argv, char** envp) { if (iPid == -1) { CUtils::PrintStatus(false, strerror(errno)); - delete pZNC; exit(1); } if (iPid > 0) { CUtils::PrintStatus(true, "[pid: " + CString::ToString(iPid) + "]"); - pZNC->WritePidFile(iPid); + ZNC.WritePidFile(iPid); CUtils::PrintMessage(CZNC::GetTag(false)); exit(0); } @@ -231,7 +223,7 @@ int main(int argc, char** argv, char** envp) { int iRet = 0; try { - iRet = pZNC->Loop(); + iRet = ZNC.Loop(); } catch (CException e) { // EX_Shutdown is thrown to exit switch (e.GetType()) { @@ -242,7 +234,5 @@ int main(int argc, char** argv, char** envp) { } } - delete pZNC; - return iRet; } diff --git a/modules/webadmin.cpp b/modules/webadmin.cpp index 730b0656..2ef499e3 100644 --- a/modules/webadmin.cpp +++ b/modules/webadmin.cpp @@ -71,7 +71,7 @@ public: return ""; } - CModules& Modules = (bGlobal) ? CZNC::New()->GetModules() : m_pUser->GetModules(); + CModules& Modules = (bGlobal) ? CZNC::Get().GetModules() : m_pUser->GetModules(); for (unsigned int a = 0; a < Modules.size(); a++) { CModule* pModule = Modules[a]; diff --git a/znc.h b/znc.h index b9e0f6a4..8ff960dc 100644 --- a/znc.h +++ b/znc.h @@ -73,9 +73,9 @@ public: // !Getters // Static allocator - static CZNC* New() { - static CZNC* pZNC = new CZNC; - return pZNC; + static CZNC& Get() { + static CZNC ZNC; + return ZNC; } CUser* FindUser(const CString& sUsername);