From b28c1f64c4e8eb15b5dd6e6329c186095e40c993 Mon Sep 17 00:00:00 2001 From: gereon Date: Sun, 9 Dec 2012 23:21:31 +0100 Subject: [PATCH] fixing a few memory issues --- src/mrmc.cpp | 3 +++ src/utility/settings.cpp | 14 ++++++-------- src/utility/settings.h | 9 ++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/mrmc.cpp b/src/mrmc.cpp index 8c3e63180..6d777c517 100644 --- a/src/mrmc.cpp +++ b/src/mrmc.cpp @@ -84,14 +84,17 @@ int main(const int argc, const char* argv[]) { if (s->isSet("help")) { std::cout << mrmc::settings::help; + delete s; return 0; } if (s->isSet("help-config")) { std::cout << mrmc::settings::helpConfigfile; + delete s; return 0; } if (s->isSet("test-prctl")) { mrmc::parser::PRCTLParser parser(s->getString("test-prctl").c_str()); + delete s; return 0; } diff --git a/src/utility/settings.cpp b/src/utility/settings.cpp index c5b84db95..1df838050 100644 --- a/src/utility/settings.cpp +++ b/src/utility/settings.cpp @@ -19,8 +19,8 @@ namespace bpo = boost::program_options; /* * static initializers */ -bpo::options_description* mrmc::settings::Settings::cli = nullptr; -bpo::options_description* mrmc::settings::Settings::conf = nullptr; +std::unique_ptr mrmc::settings::Settings::cli; +std::unique_ptr mrmc::settings::Settings::conf = nullptr; std::string mrmc::settings::Settings::binaryName = ""; mrmc::settings::Settings* mrmc::settings::Settings::inst = nullptr; @@ -51,21 +51,19 @@ Settings::Settings(const int argc, const char* argv[], const char* filename) Settings::positional.add("labfile", 1); //! Create and fill collecting options descriptions - Settings::cli = new bpo::options_description(); + Settings::cli = std::unique_ptr(new bpo::options_description()); Settings::cli->add(Settings::commandline).add(generic); - Settings::conf = new bpo::options_description(); + Settings::conf = std::unique_ptr(new bpo::options_description()); Settings::conf->add(Settings::configfile).add(generic); //! Perform first parse run and call intermediate callbacks this->firstRun(argc, argv, filename); //! Rebuild collecting options descriptions - delete Settings::cli; - Settings::cli = new bpo::options_description(); + Settings::cli = std::unique_ptr(new bpo::options_description()); Settings::cli->add(Settings::commandline).add(generic); - delete Settings::conf; - Settings::conf = new bpo::options_description(); + Settings::conf = std::unique_ptr(new bpo::options_description()); Settings::conf->add(Settings::configfile).add(generic); //! Stop if help is set diff --git a/src/utility/settings.h b/src/utility/settings.h index 993fdc241..2b07bb81e 100644 --- a/src/utility/settings.h +++ b/src/utility/settings.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "src/exceptions/InvalidSettings.h" @@ -76,7 +77,6 @@ namespace settings { */ template const T& get(const std::string &name) const { - std::cerr << "get(" << name << ")" << std::endl; if (this->vm.count(name) == 0) throw mrmc::exceptions::InvalidSettings(); return this->vm[name].as(); } @@ -141,11 +141,11 @@ namespace settings { /*! * @brief Collecting option descriptions for command line. */ - static bpo::options_description* cli; + static std::unique_ptr cli; /*! * @brief Collecting option descriptions for config file. */ - static bpo::options_description* conf; + static std::unique_ptr conf; /*! * @brief option mapping. @@ -199,8 +199,7 @@ namespace settings { Settings::inst = new Settings(argc, argv, filename); return Settings::inst; } - - + /*! * @brief Function type for functions registering new options. */