From e793a0c76d2b53987bf91a3643103b493a7cac51 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Wed, 3 Sep 2003 15:35:35 +0000 Subject: [PATCH] Fixed an error with the destructors. valgrind showed that destructor wasn't being called for single instance of FalloffFactory. --- Cantera/src/FalloffFactory.h | 8 +++++--- Cantera/src/FalloffMgr.h | 13 ++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Cantera/src/FalloffFactory.h b/Cantera/src/FalloffFactory.h index 8a7d14aa4..5c6b7c2de 100755 --- a/Cantera/src/FalloffFactory.h +++ b/Cantera/src/FalloffFactory.h @@ -102,11 +102,13 @@ namespace Cantera { } /** - * Delete the factory, and set the pointer to zero. + * Destructor doesn't do anything. We do not delete statically + * created single instance of this class here, because it would + * create an infinite loop if destructor is called for that + * single instance. Instead, to delete single instance, we + * call delete[] from FalloffMng's destructor. */ virtual ~FalloffFactory() { - delete __factory; - __factory = 0; } /** diff --git a/Cantera/src/FalloffMgr.h b/Cantera/src/FalloffMgr.h index 0ccb808cc..e25f6ff27 100755 --- a/Cantera/src/FalloffMgr.h +++ b/Cantera/src/FalloffMgr.h @@ -30,7 +30,8 @@ namespace Cantera { * falloff function calculators. If omitted, the standard factory * will be used. */ - FalloffMgr(FalloffFactory* f = 0) : m_n(0), m_n0(0), m_worksize(0) { + FalloffMgr(FalloffFactory* f = 0) : + m_factory(0), m_n(0), m_n0(0), m_worksize(0) { if (f == 0) m_factory = FalloffFactory::factory(); else m_factory = f; } @@ -42,6 +43,10 @@ namespace Cantera { virtual ~FalloffMgr(){ int i; for (i = 0; i < m_n; i++) delete m_falloff[i]; + if (m_factory) { + delete m_factory; + m_factory = 0; + } } /** @@ -114,9 +119,3 @@ namespace Cantera { } #endif - - - - - -