From 7c456589939e739c3f46e6f53da2fb8bb68ad269 Mon Sep 17 00:00:00 2001 From: psychon Date: Mon, 25 Aug 2008 14:46:22 +0000 Subject: [PATCH] Add some proper cleanup to some places in main() This adds a bunch of 'delete pZNC', turns some exit()s into returns and does some whitespace fun. kroimon (partly) gets the kudos for this, too. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1172 726aef4b-f618-498e-8847-2d620e286838 --- main.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 4020dae7..59a6ee05 100644 --- a/main.cpp +++ b/main.cpp @@ -142,18 +142,21 @@ int main(int argc, char** argv) { delete pZNC; return 0; } + if (bEncPem && !bMakePem) { CUtils::PrintError("--encrypt-pem should be used along with --makepem."); + delete pZNC; return 1; } - #endif /* HAVE_LIBSSL */ + if (bMakePass) { CString sSalt; CString sHash = CUtils::GetSaltedHashPass(sSalt); CUtils::PrintMessage("Use this in the section of your config:"); CUtils::PrintMessage("Pass = md5#" + sHash + "#" + sSalt + "#"); + delete pZNC; return 0; } @@ -181,7 +184,8 @@ int main(int argc, char** argv) { CUtils::PrintError("You are running ZNC as root! Don't do that! There are not many valid"); CUtils::PrintError("reasons for this and it can, in theory, cause great damage!"); if (!bAllowRoot) { - exit(1); + delete pZNC; + return 1; } CUtils::PrintError("You have been warned."); CUtils::PrintError("Hit CTRL+C now if you don't want to run ZNC as root."); @@ -203,7 +207,7 @@ int main(int argc, char** argv) { if (iPid == -1) { CUtils::PrintStatus(false, strerror(errno)); delete pZNC; - exit(1); + return 1; } if (iPid > 0) { @@ -212,7 +216,8 @@ int main(int argc, char** argv) { pZNC->WritePidFile(iPid); CUtils::PrintMessage(CZNC::GetTag()); - exit(0); + /* Don't destroy pZNC here or it will delete the pid file. */ + return 0; } // Redirect std in/out/err to /dev/null