Browse Source

fixing a few memory issues

tempestpy_adaptions
gereon 12 years ago
parent
commit
b28c1f64c4
  1. 3
      src/mrmc.cpp
  2. 14
      src/utility/settings.cpp
  3. 7
      src/utility/settings.h

3
src/mrmc.cpp

@ -84,14 +84,17 @@ int main(const int argc, const char* argv[]) {
if (s->isSet("help")) { if (s->isSet("help")) {
std::cout << mrmc::settings::help; std::cout << mrmc::settings::help;
delete s;
return 0; return 0;
} }
if (s->isSet("help-config")) { if (s->isSet("help-config")) {
std::cout << mrmc::settings::helpConfigfile; std::cout << mrmc::settings::helpConfigfile;
delete s;
return 0; return 0;
} }
if (s->isSet("test-prctl")) { if (s->isSet("test-prctl")) {
mrmc::parser::PRCTLParser parser(s->getString("test-prctl").c_str()); mrmc::parser::PRCTLParser parser(s->getString("test-prctl").c_str());
delete s;
return 0; return 0;
} }

14
src/utility/settings.cpp

@ -19,8 +19,8 @@ namespace bpo = boost::program_options;
/* /*
* static initializers * static initializers
*/ */
bpo::options_description* mrmc::settings::Settings::cli = nullptr;
bpo::options_description* mrmc::settings::Settings::conf = nullptr;
std::unique_ptr<bpo::options_description> mrmc::settings::Settings::cli;
std::unique_ptr<bpo::options_description> mrmc::settings::Settings::conf = nullptr;
std::string mrmc::settings::Settings::binaryName = ""; std::string mrmc::settings::Settings::binaryName = "";
mrmc::settings::Settings* mrmc::settings::Settings::inst = nullptr; 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); Settings::positional.add("labfile", 1);
//! Create and fill collecting options descriptions //! Create and fill collecting options descriptions
Settings::cli = new bpo::options_description();
Settings::cli = std::unique_ptr<bpo::options_description>(new bpo::options_description());
Settings::cli->add(Settings::commandline).add(generic); Settings::cli->add(Settings::commandline).add(generic);
Settings::conf = new bpo::options_description();
Settings::conf = std::unique_ptr<bpo::options_description>(new bpo::options_description());
Settings::conf->add(Settings::configfile).add(generic); Settings::conf->add(Settings::configfile).add(generic);
//! Perform first parse run and call intermediate callbacks //! Perform first parse run and call intermediate callbacks
this->firstRun(argc, argv, filename); this->firstRun(argc, argv, filename);
//! Rebuild collecting options descriptions //! Rebuild collecting options descriptions
delete Settings::cli;
Settings::cli = new bpo::options_description();
Settings::cli = std::unique_ptr<bpo::options_description>(new bpo::options_description());
Settings::cli->add(Settings::commandline).add(generic); Settings::cli->add(Settings::commandline).add(generic);
delete Settings::conf;
Settings::conf = new bpo::options_description();
Settings::conf = std::unique_ptr<bpo::options_description>(new bpo::options_description());
Settings::conf->add(Settings::configfile).add(generic); Settings::conf->add(Settings::configfile).add(generic);
//! Stop if help is set //! Stop if help is set

7
src/utility/settings.h

@ -11,6 +11,7 @@
#include <iostream> #include <iostream>
#include <list> #include <list>
#include <utility> #include <utility>
#include <memory>
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include "src/exceptions/InvalidSettings.h" #include "src/exceptions/InvalidSettings.h"
@ -76,7 +77,6 @@ namespace settings {
*/ */
template <typename T> template <typename T>
const T& get(const std::string &name) const { const T& get(const std::string &name) const {
std::cerr << "get(" << name << ")" << std::endl;
if (this->vm.count(name) == 0) throw mrmc::exceptions::InvalidSettings(); if (this->vm.count(name) == 0) throw mrmc::exceptions::InvalidSettings();
return this->vm[name].as<T>(); return this->vm[name].as<T>();
} }
@ -141,11 +141,11 @@ namespace settings {
/*! /*!
* @brief Collecting option descriptions for command line. * @brief Collecting option descriptions for command line.
*/ */
static bpo::options_description* cli;
static std::unique_ptr<bpo::options_description> cli;
/*! /*!
* @brief Collecting option descriptions for config file. * @brief Collecting option descriptions for config file.
*/ */
static bpo::options_description* conf;
static std::unique_ptr<bpo::options_description> conf;
/*! /*!
* @brief option mapping. * @brief option mapping.
@ -200,7 +200,6 @@ namespace settings {
return Settings::inst; return Settings::inst;
} }
/*! /*!
* @brief Function type for functions registering new options. * @brief Function type for functions registering new options.
*/ */

Loading…
Cancel
Save