From e802942be2ed4940e7a8c8dc3edc5108fde4b80c Mon Sep 17 00:00:00 2001 From: gereon Date: Thu, 13 Dec 2012 23:09:04 +0100 Subject: [PATCH] fixing memory leaks. only log4cplus left... --- src/modelChecker/EigenDtmcPrctlModelChecker.h | 1 + src/modelChecker/GmmxxDtmcPrctlModelChecker.h | 1 + src/mrmc.cpp | 8 +++++--- src/utility/settings.cpp | 2 +- src/utility/settings.h | 6 +++--- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/modelChecker/EigenDtmcPrctlModelChecker.h b/src/modelChecker/EigenDtmcPrctlModelChecker.h index 7be98d772..4730ab9cc 100644 --- a/src/modelChecker/EigenDtmcPrctlModelChecker.h +++ b/src/modelChecker/EigenDtmcPrctlModelChecker.h @@ -157,6 +157,7 @@ public: // Transform the submatric matrix to the eigen format to use its solvers Eigen::SparseMatrix* eigenSubMatrix = submatrix->toEigenSparseMatrix(); + delete submatrix; // Initialize the x vector with 0.5 for each element. This is the initial guess for // the iterative solvers. It should be safe as for all 'maybe' states we know that the diff --git a/src/modelChecker/GmmxxDtmcPrctlModelChecker.h b/src/modelChecker/GmmxxDtmcPrctlModelChecker.h index ff332b566..f98c169da 100644 --- a/src/modelChecker/GmmxxDtmcPrctlModelChecker.h +++ b/src/modelChecker/GmmxxDtmcPrctlModelChecker.h @@ -127,6 +127,7 @@ public: // Transform the submatrix to the gmm++ format to use its solvers. gmm::csr_matrix* gmmxxMatrix = submatrix->toGMMXXSparseMatrix(); + delete submatrix; // Initialize the x vector with 0.5 for each element. This is the initial guess for // the iterative solvers. It should be safe as for all 'maybe' states we know that the diff --git a/src/mrmc.cpp b/src/mrmc.cpp index d01191f00..aa9767b29 100644 --- a/src/mrmc.cpp +++ b/src/mrmc.cpp @@ -115,9 +115,10 @@ int main(const int argc, const char* argv[]) { mrmc::formula::AP* ap = new mrmc::formula::AP(std::string("observe0Greater1")); mrmc::formula::Until* until = new mrmc::formula::Until(trueFormula, ap); - std::vector* eigenResult = NULL; + try { - eigenResult = mc.checkPathFormula(*until); + std::vector* eigenResult = mc.checkPathFormula(*until); + delete eigenResult; } catch (mrmc::exceptions::NoConvergence& nce) { // solver did not converge LOG4CPLUS_ERROR(logger, "EigenDtmcPrctlModelChecker did not converge with " << nce.getIterationCount() << " of max. " << nce.getMaxIterationCount() << "Iterations!"); @@ -130,7 +131,8 @@ int main(const int argc, const char* argv[]) { mrmc::formula::AP* trueFormulaG = new mrmc::formula::AP(std::string("true")); mrmc::formula::AP* apG = new mrmc::formula::AP(std::string("observe0Greater1")); mrmc::formula::Until* untilG = new mrmc::formula::Until(trueFormulaG, apG); - std::vector* gmmResult = mcG.checkPathFormula(*untilG); + std::vector* vec = mcG.checkPathFormula(*untilG); + delete vec; delete untilG; /* diff --git a/src/utility/settings.cpp b/src/utility/settings.cpp index 525f9a02f..1a03cc98d 100644 --- a/src/utility/settings.cpp +++ b/src/utility/settings.cpp @@ -27,7 +27,7 @@ std::unique_ptr mrmc::settings::Settings::desc = nullp std::string mrmc::settings::Settings::binaryName = ""; mrmc::settings::Settings* mrmc::settings::Settings::inst = nullptr; -std::map< std::pair, bpo::options_description* > mrmc::settings::Settings::modules; +std::map< std::pair, std::shared_ptr > mrmc::settings::Settings::modules; /*! * The constructor fills the option descriptions, parses the diff --git a/src/utility/settings.h b/src/utility/settings.h index 0d634697f..d7387392d 100644 --- a/src/utility/settings.h +++ b/src/utility/settings.h @@ -113,9 +113,9 @@ namespace settings { // build description name std::stringstream str; str << T::getModuleName() << " (" << trigger.first << " = " << trigger.second << ")"; - bpo::options_description* desc = new bpo::options_description(str.str()); + std::shared_ptr desc = std::shared_ptr(new bpo::options_description(str.str())); // but options - T::putOptions(desc); + T::putOptions(desc.get()); // store Settings::modules[ trigger ] = desc; } @@ -159,7 +159,7 @@ namespace settings { /*! * @brief Contains option descriptions for all modules. */ - static std::map< std::pair< std::string, std::string >, bpo::options_description* > modules; + static std::map< std::pair< std::string, std::string >, std::shared_ptr > modules; /*! * @brief option mapping.