From 7913e6139f4c0e38532bd3df2b99a46c66bdcd5d Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tristan.matthews@savoirfairelinux.com> Date: Thu, 2 Jun 2011 13:59:16 -0400 Subject: [PATCH] * #6000: fix memory leak of args object --- sflphone-common/src/main.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sflphone-common/src/main.cpp b/sflphone-common/src/main.cpp index 6aa34c5144..6c9d3083d6 100644 --- a/sflphone-common/src/main.cpp +++ b/sflphone-common/src/main.cpp @@ -33,6 +33,7 @@ #include <libintl.h> #include <cstring> #include <iostream> +#include <memory> // for auto_ptr #include <string> #include <dirent.h> #include <sys/stat.h> @@ -71,7 +72,10 @@ main (int argc, char **argv) Logger::setConsoleLog (false); Logger::setDebugMode (false); - CommandOptionParse * args = makeCommandOptionParse (argc, argv, ""); + // makeCommandOptionParse allocates the object with operator new, so + // auto_ptr is fine in this context. + // TODO: This should eventually be replaced with std::unique_ptr for C++0x + std::auto_ptr<CommandOptionParse> args(makeCommandOptionParse (argc, argv, "")); printf ("SFLphone Daemon %s, by Savoir-Faire Linux 2004-2011\n", VERSION); printf ("http://www.sflphone.org/\n"); @@ -80,8 +84,7 @@ main (int argc, char **argv) std::cerr << args->printUsage(); ::exit (0); } - - if (args->argsHaveError()) { + else if (args->argsHaveError()) { std::cerr << args->printErrors(); std::cerr << args->printUsage(); ::exit (1); @@ -97,8 +100,6 @@ main (int argc, char **argv) Logger::setDebugMode (true); } - delete args; - FILE *fp; char homepid[128]; char sfldir[128]; -- GitLab