Salome HOME
CCAR: remove some memory leaks in DF and NamingService
authorcaremoli <caremoli>
Tue, 8 Sep 2009 17:04:07 +0000 (17:04 +0000)
committercaremoli <caremoli>
Tue, 8 Sep 2009 17:04:07 +0000 (17:04 +0000)
      add helper methods to NamingService and LifeCycle

src/DF/DF_Attribute.cxx
src/DF/DF_Document.cxx
src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx
src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx
src/NamingService/SALOME_NamingService.cxx
src/NamingService/SALOME_NamingService.hxx

index 64cd7de7b8530c8adfb96363b462c331edf1d557..a3560c60c9b6c7400b0f4f6dd9024246afdb2f82 100644 (file)
@@ -41,8 +41,9 @@ DF_Attribute::~DF_Attribute()
     map<string, DF_Attribute*>::iterator mi;
     for(mi =_node->_attributes.begin(); mi != _node->_attributes.end(); mi++) {
        if(mi->second == this) {
-        _node->_attributes.erase(mi);
-       }        
+         _node->_attributes.erase(mi);
+         return;
+       } 
     }
   }
 }
index 6037f4ef30d0153174bb90496e57354d79e1f5ae..68fe98559a5ddc663cd9e7953a8a224e59775092 100644 (file)
@@ -103,7 +103,7 @@ void DF_Document::Clear()
     delete vn[i];
 
   _root._node->Reset();
-  delete _root._node;
+  _root.Nullify();
 }
 
 //Returns true if this document is empty
index 197da12db9a570005b092792b73b70eaa515854a..b980df3845b6f6381d0e79a849f84403a976d656 100644 (file)
@@ -85,9 +85,11 @@ SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService *ns)
   char **argv = &xargv;
   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
   //  LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
+  _NSnew=0;
   if (!ns)
     {
       _NS = new SALOME_NamingService(orb);
+      _NSnew=_NS;
     }
   else _NS = ns;
   //add try catch
@@ -115,6 +117,7 @@ SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService *ns)
 
 SALOME_LifeCycleCORBA::~SALOME_LifeCycleCORBA()
 {
+  if(_NSnew)delete _NSnew;
 }
 
 //=============================================================================
@@ -734,3 +737,21 @@ void SALOME_LifeCycleCORBA::copyFile(const char* hostSrc, const char* fileSrc, c
   containerDest->copyFile(containerSrc,fileSrc,fileDest);
 }
 
+/*! \brief get the naming service used by the life cycle
+ *
+ *  \return the naming service
+ */
+SALOME_NamingService * SALOME_LifeCycleCORBA::namingService()
+{
+  return _NS;
+}
+
+/*! \brief get the orb used by the life cycle
+ *
+ *  \return the orb
+ */
+CORBA::ORB_ptr SALOME_LifeCycleCORBA::orb()
+{
+  return _NS->orb();
+}
+
index 4083c428b6919d0bfe50a5f9ea5fb282839f0b33..c22385796a91dd179518b919cf24a118f57d1f96 100644 (file)
@@ -102,6 +102,8 @@ public:
 
   Engines::ContainerManager_ptr getContainerManager();
   Engines::ResourcesManager_ptr getResourcesManager();
+  SALOME_NamingService * namingService();
+  CORBA::ORB_ptr orb();
   void copyFile(const char* hostSrc, const char* fileSrc, const char* hostDest, const char* fileDest);
 
   void shutdownServers();
@@ -126,6 +128,7 @@ protected:
                 int studyId);
   
   SALOME_NamingService *_NS;
+  SALOME_NamingService *_NSnew;
   Engines::ContainerManager_var _ContManager;
   Engines::ResourcesManager_var _ResManager;
   
index 9b1d479f5e7b4046252d1ad30621dab61940b481..70d337008f190dc5fe79c3599db7a518e6c35ba4 100644 (file)
@@ -90,6 +90,7 @@ SALOME_NamingService::~SALOME_NamingService()
  * 
  *  Initializes ORB reference and naming service root context.
  *  For use after default constructor.
+ *  If param orb is null, the orb is initialized
  *  \param orb CORBA::ORB_ptr arguments
  */ 
 // ============================================================================
@@ -99,7 +100,13 @@ void SALOME_NamingService::init_orb(CORBA::ORB_ptr orb)
   MESSAGE("SALOME_NamingService initialisation");
 
   Utils_Locker lock (&_myMutex);
-  _orb = CORBA::ORB::_duplicate(orb);
+  if(orb)
+    _orb = CORBA::ORB::_duplicate(orb);
+  else
+    {
+      int argc=0;
+      _orb = CORBA::ORB_init(argc, 0); // Here we make the assumption that the orb has already been initialized
+    }
 
   _initialize_root_context();
 }
@@ -1825,3 +1832,12 @@ char * SALOME_NamingService::getIORaddr()
   return _orb->object_to_string(_root_context);
 }
 
+/*! \brief get the orb used by the naming service
+ *
+ *  \return the orb
+ */
+CORBA::ORB_ptr SALOME_NamingService::orb()
+{
+  return _orb;
+}
+
index 6e54c5f7dc9db0fc91763649c69a33f4c569fb82..df06b2e1c8317a4ae93fa0a19b2aeae82b60aa40 100644 (file)
@@ -48,7 +48,7 @@ public:
 
   virtual ~SALOME_NamingService();
 
-  void init_orb(CORBA::ORB_ptr orb);
+  void init_orb(CORBA::ORB_ptr orb=0);
   void Register(CORBA::Object_ptr ObjRef,
                const char* Path) 
     throw(ServiceUnreachable);
@@ -91,6 +91,7 @@ public:
   virtual void Destroy_FullDirectory(const char* Path)
     throw(ServiceUnreachable);
   char* getIORaddr();
+  CORBA::ORB_ptr orb();
 
 protected:
   Utils_Mutex _myMutex;