From: caremoli Date: Tue, 8 Sep 2009 17:04:07 +0000 (+0000) Subject: CCAR: remove some memory leaks in DF and NamingService X-Git-Tag: V5_1_3rc1~69 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8544140d1bd61e43d8cd93893ce7c73ba2f675b2;p=modules%2Fkernel.git CCAR: remove some memory leaks in DF and NamingService add helper methods to NamingService and LifeCycle --- diff --git a/src/DF/DF_Attribute.cxx b/src/DF/DF_Attribute.cxx index 64cd7de7b..a3560c60c 100644 --- a/src/DF/DF_Attribute.cxx +++ b/src/DF/DF_Attribute.cxx @@ -41,8 +41,9 @@ DF_Attribute::~DF_Attribute() map::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; + } } } } diff --git a/src/DF/DF_Document.cxx b/src/DF/DF_Document.cxx index 6037f4ef3..68fe98559 100644 --- a/src/DF/DF_Document.cxx +++ b/src/DF/DF_Document.cxx @@ -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 diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index 197da12db..b980df384 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -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(); +} + diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx index 4083c428b..c22385796 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx @@ -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; diff --git a/src/NamingService/SALOME_NamingService.cxx b/src/NamingService/SALOME_NamingService.cxx index 9b1d479f5..70d337008 100644 --- a/src/NamingService/SALOME_NamingService.cxx +++ b/src/NamingService/SALOME_NamingService.cxx @@ -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; +} + diff --git a/src/NamingService/SALOME_NamingService.hxx b/src/NamingService/SALOME_NamingService.hxx index 6e54c5f7d..df06b2e1c 100644 --- a/src/NamingService/SALOME_NamingService.hxx +++ b/src/NamingService/SALOME_NamingService.hxx @@ -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;