diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2014-10-04 22:27:45 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2014-10-04 22:27:45 +0200 |
commit | 8f97e74456a2698d59471682c63929b1af124230 (patch) | |
tree | 2fa2cab96617e0b6dc6ce835939a07a5000f3cdc | |
parent | 578f8d8b0bec9ba3e5a1f8b4bf26b66f58dd6752 (diff) | |
download | crawler-8f97e74456a2698d59471682c63929b1af124230.tar.gz crawler-8f97e74456a2698d59471682c63929b1af124230.tar.bz2 |
fixed code in destructor of BaseModuleLoader, was a little bit weird
-rwxr-xr-x | include/module/ModuleLoader.hpp | 24 | ||||
-rw-r--r-- | 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 |