]> Creatis software - cpPlugins.git/blobdiff - appli/examples/plugins/example_LoadPluginsDirectory.cxx
Bug smashed like a boss
[cpPlugins.git] / appli / examples / plugins / example_LoadPluginsDirectory.cxx
index 803d3909b89c2ad7b66a6a8a55c734e0ca7f6b4a..99f4b62a4c553eaf0a533eca4c3567042acc3018 100644 (file)
@@ -5,32 +5,39 @@ int main( int argc, char* argv[] )
 {
   if( argc < 2 )
   {
-    std::cerr << "Usage: " << argv[ 0 ] << " plugins_libraries_dir" << std::endl;
+    std::cerr
+      << "Usage: " << argv[ 0 ] << " plugins_libraries_dir" << std::endl;
     return( 1 );
 
   } // fi
 
   // Load interface
-  cpPlugins::Interface interface;
+  cpPlugins::Interface* interface = NULL;
   try
   {
-    interface.LoadPluginDir( argv[ 1 ] );
+    interface = new cpPlugins::Interface( );
+    interface->LoadPluginDir( argv[ 1 ] );
   }
   catch( std::exception& err )
   {
-    std::cerr << "Error caught: " << err.what( ) << std::endl;
+    if( interface != NULL )
+      delete interface;
+    std::cerr
+      << "Error caught: "
+      << err.what( )
+      << std::endl;
     return( 1 );
 
   } // yrt
 
   // Show loaded plugins
-  auto plugins = interface.GetPlugins( );
+  auto plugins = interface->GetPlugins( );
   for( auto pIt = plugins.begin( ); pIt != plugins.end( ); ++pIt )
     std::cout << "Plugin: " << *pIt << std::endl;
   std::cout << std::endl;
 
   // Show loaded filters
-  auto filters = interface.GetFilters( );
+  auto filters = interface->GetFilters( );
   for( auto cIt = filters.begin( ); cIt != filters.end( ); ++cIt )
   {
     std::cout << "Category: " << cIt->first << std::endl;
@@ -40,6 +47,9 @@ int main( int argc, char* argv[] )
         << std::endl;
 
   } // rof
+
+  // Free all and finish
+  delete interface;
   return( 0 );
 }