diff --git a/Cantera/src/transport/TransportFactory.cpp b/Cantera/src/transport/TransportFactory.cpp index 9f247df6c..5587e4d2e 100755 --- a/Cantera/src/transport/TransportFactory.cpp +++ b/Cantera/src/transport/TransportFactory.cpp @@ -202,11 +202,32 @@ namespace Cantera { m_models["None"] = 0; } + + /** + * Destructor + * + * 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. + * However, we do have a malloced pointer to m_integrals + * that does need to be explicitly deleted. + */ TransportFactory::~TransportFactory() { - delete __factory; - __factory = 0; - delete m_integrals; - m_integrals = 0; + if (m_integrals) { + delete m_integrals; + m_integrals = 0; + } + } + + /** + * This static function deletes the statically malloced instance. + */ + void TransportFactory::deleteTransportFactory() { + if (__factory) { + delete __factory; + __factory = 0; + } } /** diff --git a/Cantera/src/transport/TransportFactory.h b/Cantera/src/transport/TransportFactory.h index 651eda512..dd180bfbe 100755 --- a/Cantera/src/transport/TransportFactory.h +++ b/Cantera/src/transport/TransportFactory.h @@ -28,6 +28,7 @@ #include #include #include +#include using namespace std; @@ -96,11 +97,21 @@ namespace Cantera { return __factory; } + /** + * Deletes the statically malloced instance. + */ + static void deleteTransportFactory(); + /** - * Destructor. Deletes the TransportFactory instance pointed - * to by __factory, and sets __factory to NULL. + * Destructor + * + * 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. */ virtual ~TransportFactory(); + /// Build a new transport manager virtual Transport* @@ -178,7 +189,15 @@ namespace Cantera { if (f == 0) { f = TransportFactory::factory(); } - return f->newTransport(transportModel, thermo, loglevel); + Transport* ptr = f->newTransport(transportModel, thermo, loglevel); + /* + * Note: We delete the static __factory instance here, instead of in + * appdelete() in misc.cpp, to avoid linking problems involving + * the need for multiple cantera and transport library statements + * for applications that don't have transport in them. + */ + TransportFactory::deleteTransportFactory(); + return ptr; }