]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
patchShutdownAndLeaks.dat by Christian CAREMOLI.
authorjfa <jfa@opencascade.com>
Thu, 31 Jan 2008 11:22:40 +0000 (11:22 +0000)
committerjfa <jfa@opencascade.com>
Thu, 31 Jan 2008 11:22:40 +0000 (11:22 +0000)
src/Session/SALOME_Session_Server.cxx
src/Session/Session_ServerLauncher.cxx
src/Session/Session_ServerThread.cxx
src/Session/Session_Session_i.cxx

index 635c5724f2ff163576ed1721ee1dd786fa5d8fd9..01bed2abd66b387076274f9a158234aa666d2e74 100755 (executable)
@@ -310,6 +310,33 @@ bool isFound( const char* str, int argc, char** argv )
   return false;
 }
 
+void killOmniNames( )
+{
+    QString fileName( ::getenv ("OMNIORB_CONFIG") );
+    QString portNumber;
+    if ( !fileName.isEmpty() ) 
+    {
+      QFile aFile( fileName );
+      if ( aFile.open(IO_ReadOnly) ) {
+        QRegExp re("InitRef = .*:([0-9]+)$");
+        QTextStream stream ( &aFile );
+        while ( !stream.atEnd() ) {
+          QString textLine = stream.readLine();
+          if ( re.search( textLine ) > -1 )
+            portNumber = re.cap(1);
+        }
+        aFile.close();
+      }
+    }
+
+    if ( !portNumber.isEmpty() ) 
+    {
+      QString cmd ;
+      cmd = QString( "ps -eo pid,command | grep -v grep | grep -E \"omniNames.*%1\" | awk '{cmd=sprintf(\"kill -9 %s\",$1); system(cmd)}'" ).arg( portNumber );
+      system ( cmd.latin1() );
+    }
+}
+
 // shutdown standalone servers
 void shutdownServers( SALOME_NamingService* theNS )
 {
@@ -367,40 +394,22 @@ void shutdownServers( SALOME_NamingService* theNS )
     CORBA::Object_var objSDS = theNS->Resolve("/myStudyManager");
     SALOMEDS::StudyManager_var studyManager = SALOMEDS::StudyManager::_narrow(objSDS) ;
     if ( !CORBA::is_nil(studyManager) && ( session->getPID() != studyManager->getPID() ) )
-      studyManager->ShutdownWithExit();
+      studyManager->Shutdown();
     
     // 7) ModuleCatalog
     CORBA::Object_var objMC=theNS->Resolve("/Kernel/ModulCatalog");
     SALOME_ModuleCatalog::ModuleCatalog_var catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objMC);
     if ( !CORBA::is_nil(catalog) && ( session->getPID() != catalog->getPID() ) )
-      catalog->ShutdownWithExit();
+      catalog->shutdown();
     
     // 8) Registry
     CORBA::Object_var objR = theNS->Resolve("/Registry");
     Registry::Components_var registry = Registry::Components::_narrow(objR);
     if ( !CORBA::is_nil(registry) && ( session->getPID() != registry->getPID() ) )
-      registry->end();
+      registry->Shutdown();
     
     // 9) Kill OmniNames
-    QString fileName( ::getenv ("OMNIORB_CONFIG") );
-    QString portNumber;
-    if ( !fileName.isEmpty() ) {
-      QFile aFile( fileName );
-      if ( aFile.open(IO_ReadOnly) ) {
-       QRegExp re("InitRef = .*:([0-9]+)$");
-       QTextStream stream ( &aFile );
-       while ( !stream.atEnd() ) {
-         QString textLine = stream.readLine();
-         if ( re.search( textLine ) > -1 )
-           portNumber = re.cap(1);
-       }
-       aFile.close();
-      }
-    }
-    if ( !portNumber.isEmpty() ) {
-      QString cmd = QString( "ps -eo pid,command | grep -v grep | grep -E \"omniNames.*%1\" | awk '{cmd=sprintf(\"kill -9 %s\",$1); system(cmd)}'" ).arg( portNumber );
-      system ( cmd.latin1() );
-    } 
+    //killOmniNames();
 
   }
 }
@@ -670,8 +679,19 @@ int main( int argc, char **argv )
   delete myServerLauncher;
   delete _NS;
 
-  LocalTraceBufferPool *bp1 = LocalTraceBufferPool::instance();
-  LocalTraceBufferPool::deleteInstance(bp1);
+  PyGILState_STATE gstate = PyGILState_Ensure();
+  Py_Finalize();
+
+  try 
+    {
+      orb->destroy();
+    }
+  catch(...) 
+    {
+      std::cerr << "Caught unexpected exception on destroy : ignored !!" << std::endl;
+    }
+
+  killOmniNames();
 
   return result;
 }
index 3909efc014a4faffe49104a16f1c95a7e20d81a8..c13c71a7a008c37c6995b45a5f1e387f57fa1656 100755 (executable)
@@ -96,7 +96,7 @@ void Session_ServerLauncher::run()
   _ServerLaunch->wakeAll();
 
   // run ORB
-  _orb->run(); // this thread waits, during omniORB process events
+  //_orb->run(); // No need to call orb->run() : it waits on a lock. Qt is already waiting in the mainloop.
 }
 
 /*! 
index fcdcaccebcae0f44aabaee704ee9835d446c541d..c29a4807dd94e90a3fa8aafa67891514331a41ac 100755 (executable)
@@ -193,9 +193,10 @@ void Session_ServerThread::ActivateModuleCatalog(int argc,
 
       // Tell the POA that the objects are ready to accept requests.
 
-      _root_poa->activate_object (Catalogue_i);
+      PortableServer::ObjectId_var id= _root_poa->activate_object (Catalogue_i);
+      Catalogue_i->_remove_ref();
 
-      CORBA::Object_ptr myCata = Catalogue_i->_this();
+      CORBA::Object_var myCata = Catalogue_i->_this();
       _NS->Register(myCata ,"/Kernel/ModulCatalog");
     }
   catch(CORBA::SystemException&)
@@ -430,10 +431,11 @@ void Session_ServerThread::ActivateEngine(int /*argc*/, char ** /*argv*/)
     {
       MESSAGE("SalomeApp_Engine thread started");
       SalomeApp_Engine_i* anEngine = new SalomeApp_Engine_i();
-      /*PortableServer::ObjectId_var id = */_root_poa->activate_object( anEngine );
+      PortableServer::ObjectId_var id =_root_poa->activate_object( anEngine );
       MESSAGE("poa->activate_object( SalomeApp_Engine )");
 
       CORBA::Object_var obj = anEngine->_this();
+      anEngine->_remove_ref();
       _NS->Register( obj ,"/SalomeAppEngine");
 
     }
@@ -493,6 +495,7 @@ void Session_SessionThread::ActivateSession(int argc,
 
       CORBA::Object_var obj = mySALOME_Session->_this();
       CORBA::String_var sior(_orb->object_to_string(obj));
+      mySALOME_Session->_remove_ref();
 
       mySALOME_Session->NSregister();
     }
index 81787737ebef0229b9b3f129bc86a245891c16b1..92da744bc6199d5f110926b58b8e4afde38ba8bf 100755 (executable)
@@ -64,6 +64,7 @@ SALOME_Session_i::SALOME_Session_i(int argc,
   _poa = PortableServer::POA::_duplicate(poa) ;
   _GUIMutex = GUIMutex;
   _GUILauncher = GUILauncher;
+  _NS = new SALOME_NamingService(_orb);
   //MESSAGE("constructor end");
 }
 
@@ -87,6 +88,7 @@ Engines::Component_ptr SALOME_Session_i::GetComponent(const char* theLibraryName
 */
 SALOME_Session_i::~SALOME_Session_i()
 {
+  delete _NS;
   //MESSAGE("destructor end");
 }
 
@@ -96,10 +98,10 @@ SALOME_Session_i::~SALOME_Session_i()
 */
 void SALOME_Session_i::NSregister()
 {
-  SALOME::Session_ptr pSession = SALOME::Session::_narrow(_this());
+  CORBA::Object_var obref=_this();
+  SALOME::Session_var pSession = SALOME::Session::_narrow(obref);
   try
     {
-      _NS = new SALOME_NamingService(_orb);
       _NS->Register(pSession, "/Kernel/Session");
     }
   catch (ServiceUnreachable&)