From 8f97e74456a2698d59471682c63929b1af124230 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 4 Oct 2014 22:27:45 +0200 Subject: fixed code in destructor of BaseModuleLoader, was a little bit weird --- include/module/ModuleLoader.hpp | 24 +++++++++++++----------- tests/modules/test4.MUST | 1 + 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/include/module/ModuleLoader.hpp b/include/module/ModuleLoader.hpp index 02b368e..9626972 100755 --- a/include/module/ModuleLoader.hpp +++ b/include/module/ModuleLoader.hpp @@ -83,26 +83,28 @@ class BaseModuleLoader { if( m.registry->initModule != 0 ) { m.registry->initModule( ); } - + m_modules.insert( std::make_pair( m.registry->name, m ) ); } } virtual ~BaseModuleLoader< Interface, CtorParams >( ) { - for( typename mapType::iterator it = m_modules.begin( ); it != m_modules.end( ); it++ ) { - if( (*it).second.handle ) { - if( (*it).second.registry->destroyModule != 0 ) { - (*it).second.registry->destroyModule( ); - } - + // KLUDGE: we (ab)use the list of modules to remember the destructors + // of derived classes to be called, This should be changed.. + // So we inspect only the being of the module list here. + typename mapType::iterator it = m_modules.begin( ); + if( (*it).second.registry ) { + if( (*it).second.registry->destroyModule != 0 ) { + (*it).second.registry->destroyModule( ); + } + } + if( (*it).second.handle ) { #ifndef _WIN32 - dlclose( (*it).second.handle ); + dlclose( (*it).second.handle ); #else - (void)FreeLibrary( (*it).second.handle ); + (void)FreeLibrary( (*it).second.handle ); #endif - (*it).second.handle = 0; - } } } diff --git a/tests/modules/test4.MUST b/tests/modules/test4.MUST index 2a45d20..a675dba 100644 --- a/tests/modules/test4.MUST +++ b/tests/modules/test4.MUST @@ -3,3 +3,4 @@ test4: Module 4 initModule called test4: hello from main test4: hello world from module test4: Module 4 destroyModule called +Destroyed common object -- cgit v1.2.3-54-g00ecf