From bb3675e75c9787a864557ff659b134384273dca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Tue, 9 Mar 2010 17:08:46 +0100 Subject: [PATCH] K-order DLL, DynamicDLL class: removed memory leaks --- mex/sources/k_order_perturbation/dynamic_dll.cc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/mex/sources/k_order_perturbation/dynamic_dll.cc b/mex/sources/k_order_perturbation/dynamic_dll.cc index e35d13883..001ee6949 100644 --- a/mex/sources/k_order_perturbation/dynamic_dll.cc +++ b/mex/sources/k_order_perturbation/dynamic_dll.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2009 Dynare Team + * Copyright (C) 2008-2010 Dynare Team * * This file is part of Dynare. * @@ -111,12 +111,8 @@ DynamicModelDLL::eval(const Vector &y, const TwoDMatrix &x, const Vector *modPa if (g1 != NULL) { - if (g1->nrows() != length) // dummy - { - delete g1; - g1 = new TwoDMatrix(length, jcols); // and get a new one - g1->zeros(); - } + if (g1->nrows() != length) + throw DynareException(__FILE__, __LINE__, "DLL Error: g1 has wrong size"); dg1 = const_cast(g1->base()); } if (g2 != NULL) @@ -147,7 +143,7 @@ DynamicModelDLL::eval(const Vector &y, const Vector &x, const Vector *modParams, * when calling _dynamic(z,x,params,it_) x must be equal to * zeros(M_.maximum_lag+1,M_.exo_nbr) **/ - TwoDMatrix &mx = *(new TwoDMatrix(nMax_lag+1, nExog)); + TwoDMatrix mx(nMax_lag+1, nExog); mx.zeros(); // initialise shocks to 0s eval(y, mx, modParams, nMax_lag, residual, g1, g2, g3);