Commit 9dce3b83 authored by Sébastien Villemot's avatar Sébastien Villemot

Fix memory leak in k-order DLL related to DynamicModelAC instantiation

Adapted from 50a09a68, but keeping C++03
compatibility.
parent 8b7afbae
...@@ -21,6 +21,10 @@ ...@@ -21,6 +21,10 @@
#include "dynamic_abstract_class.hh" #include "dynamic_abstract_class.hh"
DynamicModelAC::~DynamicModelAC()
{
}
void void
DynamicModelAC::copyDoubleIntoTwoDMatData(double *dm, TwoDMatrix *tdm, int rows, int cols) DynamicModelAC::copyDoubleIntoTwoDMatData(double *dm, TwoDMatrix *tdm, int rows, int cols)
{ {
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
class DynamicModelAC class DynamicModelAC
{ {
public: public:
virtual ~DynamicModelAC();
static double *unpackSparseMatrix(mxArray *sparseMatrix); static double *unpackSparseMatrix(mxArray *sparseMatrix);
static void copyDoubleIntoTwoDMatData(double *dm, TwoDMatrix *tdm, int rows, int cols); static void copyDoubleIntoTwoDMatData(double *dm, TwoDMatrix *tdm, int rows, int cols);
virtual void eval(const Vector &y, const Vector &x, const Vector &params, const Vector &ySteady, virtual void eval(const Vector &y, const Vector &x, const Vector &params, const Vector &ySteady,
......
...@@ -229,6 +229,7 @@ extern "C" { ...@@ -229,6 +229,7 @@ extern "C" {
THREAD_GROUP::max_parallel_threads = 2; //params.num_threads; THREAD_GROUP::max_parallel_threads = 2; //params.num_threads;
DynamicModelAC *dynamicModelFile = NULL;
try try
{ {
// make journal name and journal // make journal name and journal
...@@ -236,7 +237,6 @@ extern "C" { ...@@ -236,7 +237,6 @@ extern "C" {
jName += ".jnl"; jName += ".jnl";
Journal journal(jName.c_str()); Journal journal(jName.c_str());
DynamicModelAC *dynamicModelFile;
if (use_dll == 1) if (use_dll == 1)
dynamicModelFile = new DynamicModelDLL(fName); dynamicModelFile = new DynamicModelDLL(fName);
else else
...@@ -323,30 +323,41 @@ extern "C" { ...@@ -323,30 +323,41 @@ extern "C" {
e.print(); e.print();
ostringstream strstrm; ostringstream strstrm;
strstrm << "dynare:k_order_perturbation: Caught Kord exception: " << e.get_message(); strstrm << "dynare:k_order_perturbation: Caught Kord exception: " << e.get_message();
if (dynamicModelFile)
delete dynamicModelFile;
DYN_MEX_FUNC_ERR_MSG_TXT(strstrm.str().c_str()); DYN_MEX_FUNC_ERR_MSG_TXT(strstrm.str().c_str());
} }
catch (const TLException &e) catch (const TLException &e)
{ {
e.print(); e.print();
if (dynamicModelFile)
delete dynamicModelFile;
DYN_MEX_FUNC_ERR_MSG_TXT("dynare:k_order_perturbation: Caught TL exception"); DYN_MEX_FUNC_ERR_MSG_TXT("dynare:k_order_perturbation: Caught TL exception");
} }
catch (SylvException &e) catch (SylvException &e)
{ {
e.printMessage(); e.printMessage();
if (dynamicModelFile)
delete dynamicModelFile;
DYN_MEX_FUNC_ERR_MSG_TXT("dynare:k_order_perturbation: Caught Sylv exception"); DYN_MEX_FUNC_ERR_MSG_TXT("dynare:k_order_perturbation: Caught Sylv exception");
} }
catch (const DynareException &e) catch (const DynareException &e)
{ {
ostringstream strstrm; ostringstream strstrm;
strstrm << "dynare:k_order_perturbation: Caught KordDynare exception: " << e.message(); strstrm << "dynare:k_order_perturbation: Caught KordDynare exception: " << e.message();
if (dynamicModelFile)
delete dynamicModelFile;
DYN_MEX_FUNC_ERR_MSG_TXT(strstrm.str().c_str()); DYN_MEX_FUNC_ERR_MSG_TXT(strstrm.str().c_str());
} }
catch (const ogu::Exception &e) catch (const ogu::Exception &e)
{ {
ostringstream strstrm; ostringstream strstrm;
strstrm << "dynare:k_order_perturbation: Caught general exception: " << e.message(); strstrm << "dynare:k_order_perturbation: Caught general exception: " << e.message();
if (dynamicModelFile)
delete dynamicModelFile;
DYN_MEX_FUNC_ERR_MSG_TXT(strstrm.str().c_str()); DYN_MEX_FUNC_ERR_MSG_TXT(strstrm.str().c_str());
} }
delete dynamicModelFile;
plhs[0] = mxCreateDoubleScalar(0); plhs[0] = mxCreateDoubleScalar(0);
} // end of mexFunction() } // end of mexFunction()
} // end of extern C } // end of extern C
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment