Salome HOME
CCAR: remove memory leaks
authorcaremoli <caremoli>
Mon, 14 Sep 2009 07:58:07 +0000 (07:58 +0000)
committercaremoli <caremoli>
Mon, 14 Sep 2009 07:58:07 +0000 (07:58 +0000)
src/Registry/RegistryConnexion.cxx
src/Registry/RegistryService.cxx

index 2a505c764352622dd7260040232a5fff65ab6a7f..d7686a97bdafccf02d11b0edf6551985cae2294c 100644 (file)
@@ -43,119 +43,115 @@ using namespace std;
 
 Registry::Components_var Connexion( int argc , char **argv , const char *ptrSessionName ) throw( CommException )
 {
-       Registry::Components_var varComponents = 0 ;
-       ASSERT(ptrSessionName) ;
-       ASSERT(strlen(ptrSessionName)>0) ;
-       const char *registryName = "Registry" ;
-
-       try
-       {
-               ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
-               ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
-               CORBA::ORB_var &orb = init( argc , argv ) ;
-       
-               SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
-               ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
-               naming.init_orb( orb ) ;
-
-               // Recuperation de la reference de l'objet
-               CORBA::Object_var object = naming.Resolve( registryName ) ;
-               if(CORBA::is_nil(object)) throw CommException( "unable to find the RegistryService" ) ;
-
-               // Specialisation de l'objet generique
-               varComponents = Registry::Components::_narrow( object ) ;
-               ASSERT(! CORBA::is_nil(varComponents)) ;
-       }
-       catch( ... )
-       {
-               throw CommException ( "NamingService Connexion Error" ) ;
-       }
-       return varComponents ;
+        Registry::Components_var varComponents = 0 ;
+        ASSERT(ptrSessionName) ;
+        ASSERT(strlen(ptrSessionName)>0) ;
+        const char *registryName = "Registry" ;
+
+        try
+        {
+                ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
+                ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
+                CORBA::ORB_var &orb = init( argc , argv ) ;
+        
+                SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
+                ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
+                naming.init_orb( orb ) ;
+
+                // Recuperation de la reference de l'objet
+                CORBA::Object_var object = naming.Resolve( registryName ) ;
+                if(CORBA::is_nil(object)) throw CommException( "unable to find the RegistryService" ) ;
+
+                // Specialisation de l'objet generique
+                varComponents = Registry::Components::_narrow( object ) ;
+                ASSERT(! CORBA::is_nil(varComponents)) ;
+        }
+        catch( ... )
+        {
+                throw CommException ( "NamingService Connexion Error" ) ;
+        }
+        return varComponents ;
 }
 
 
 RegistryConnexion::RegistryConnexion( int argc , char **argv , const char *ior , const char *ptrSessionName, const char *componentName ): \
-       _Ior(duplicate(ior)), _VarComponents( Connexion(argc,argv,ptrSessionName) ), _SessionName(ptrSessionName),_Name(""), _Id(0)
+        _Ior(duplicate(ior)), _VarComponents( Connexion(argc,argv,ptrSessionName) ), _SessionName(ptrSessionName),_Name(""), _Id(0)
 {
-       this->add( componentName ) ;
+        this->add( componentName ) ;
 }
 
 
 RegistryConnexion::RegistryConnexion( void ): _Ior(0), _VarComponents( 0 ), _Name(""), _Id(0)
 {
-       INTERRUPTION(EXIT_FAILURE) ;
+        INTERRUPTION(EXIT_FAILURE) ;
 }
 
 
 RegistryConnexion::~RegistryConnexion()
 {
-       BEGIN_OF("RegistryConnexion::~RegistryConnexion()" ) ;
-       if( _Id != 0 )
-       {
-               ASSERT(_SessionName!="" ) ;
-               ASSERT(_Name!="" ) ;
-               _VarComponents->remove( _Id ) ;
-       }
-       _Id   = 0 ;
-#ifndef WIN32
-       delete [] _Ior;
-#else
-       delete [] (char*) _Ior;
-#endif
-       _Ior = 0;
-       _SessionName = "";
-       _Name = "" ;
-       END_OF("RegistryConnexion::~RegistryConnexion()" ) ;
+        BEGIN_OF("RegistryConnexion::~RegistryConnexion()" ) ;
+        if( _Id != 0 )
+        {
+                ASSERT(_SessionName!="" ) ;
+                ASSERT(_Name!="" ) ;
+                _VarComponents->remove( _Id ) ;
+        }
+        _Id   = 0 ;
+        delete [] (char*) _Ior;
+        _Ior = 0;
+        _SessionName = "";
+        _Name = "" ;
+        END_OF("RegistryConnexion::~RegistryConnexion()" ) ;
 }
 
 
 void RegistryConnexion::add( const char *aName )
 {
-       ASSERT(_SessionName!="" ) ;
-       ASSERT(_Name=="" ) ;
-       ASSERT(_Id==0 ) ;
-       ASSERT(aName) ;
-       SCRUTE(aName) ;
-       ASSERT(strlen( aName )>0) ;
-
-       const Identity lesInfos( aName ) ;
-       Registry::Infos infos ;
-               infos.name      = CORBA::string_dup( lesInfos.name() ) ;
-               infos.pid       = lesInfos.pid() ;
-               infos.machine   = CORBA::string_dup( lesInfos.host_char() ) ;
-               infos.adip      = CORBA::string_dup( lesInfos.adip() ) ;
-               infos.uid       = (long)lesInfos.uid() ;
-               infos.pwname    = CORBA::string_dup( lesInfos.pwname() ) ;
-               infos.tc_start  = lesInfos.start() ;
-               infos.tc_hello  = 0 ;
-               infos.tc_end    = 0 ;
-               infos.difftime  = 0 ;
-               infos.cdir      = CORBA::string_dup( lesInfos.rep() ) ;
-               infos.status    = -1 ;
-               infos.ior       = CORBA::string_dup(_Ior);
-
-       ASSERT(!CORBA::is_nil(this->_VarComponents)) ;
-
-       CORBA::ULong id = _VarComponents->add( infos ) ;
-
-       SCRUTE(aName) ; SCRUTE(id) ;
-       ASSERT(id) ;
-
-       _Id   = id ;
-       _Name = aName ;
-
-       return ;
+        ASSERT(_SessionName!="" ) ;
+        ASSERT(_Name=="" ) ;
+        ASSERT(_Id==0 ) ;
+        ASSERT(aName) ;
+        SCRUTE(aName) ;
+        ASSERT(strlen( aName )>0) ;
+
+        const Identity lesInfos( aName ) ;
+        Registry::Infos infos ;
+                infos.name        = CORBA::string_dup( lesInfos.name() ) ;
+                infos.pid        = lesInfos.pid() ;
+                infos.machine        = CORBA::string_dup( lesInfos.host_char() ) ;
+                infos.adip        = CORBA::string_dup( lesInfos.adip() ) ;
+                infos.uid        = (long)lesInfos.uid() ;
+                infos.pwname        = CORBA::string_dup( lesInfos.pwname() ) ;
+                infos.tc_start        = lesInfos.start() ;
+                infos.tc_hello        = 0 ;
+                infos.tc_end        = 0 ;
+                infos.difftime        = 0 ;
+                infos.cdir        = CORBA::string_dup( lesInfos.rep() ) ;
+                infos.status        = -1 ;
+                infos.ior        = CORBA::string_dup(_Ior);
+
+        ASSERT(!CORBA::is_nil(this->_VarComponents)) ;
+
+        CORBA::ULong id = _VarComponents->add( infos ) ;
+
+        SCRUTE(aName) ; SCRUTE(id) ;
+        ASSERT(id) ;
+
+        _Id   = id ;
+        _Name = aName ;
+
+        return ;
 }
 
 
 void RegistryConnexion::remove( void )
 {
-       ASSERT(_Id>0) ;
-       ASSERT(!CORBA::is_nil(this->_VarComponents)) ;
-       _VarComponents->remove( _Id ) ;
+        ASSERT(_Id>0) ;
+        ASSERT(!CORBA::is_nil(this->_VarComponents)) ;
+        _VarComponents->remove( _Id ) ;
 
-       _Name = "" ;
-       _Id   = 0 ;
+        _Name = "" ;
+        _Id   = 0 ;
 
-       return ;
+        return ;
 }
index d85e1e7558fe5f35817cce161a048fc0457526a3..0dd569c61ff2b70c0914a211eb54dc50ef6820ea 100644 (file)
@@ -42,223 +42,195 @@ extern "C"
 using namespace std;
 
 /* ------------------------------*/
-/* Constructeurs et Destructeurs */
+/* Constructors and Destructors  */
 /* ------------------------------*/
 
 RegistryService::RegistryService( void ) : _SessionName(0), _Compteur(0)
 {
-       MESSAGE("Passage dans RegistryService::RegistryService()") ;
-       _orb = CORBA::ORB::_nil();
+        MESSAGE("RegistryService::RegistryService()") ;
+        _orb = CORBA::ORB::_nil();
 }
 
-
 RegistryService::~RegistryService()
 {
-       BEGIN_OF("RegistryService::~RegistryService()") ;
-       map<int,client_infos *>::iterator im;
-       for (im=_reg.begin();im!=_reg.end(); im++)
-        {
-#if defined(_DEBUG_) || defined(_DEBUG)
-               const client_infos &lesInfos = *(*im).second ;
-               MESSAGE("Deletion") ; SCRUTE( lesInfos._name ) ;
-#endif
-               _reg.erase ( im ) ;
-       }
-       ASSERT(_reg.size()==0) ;
-       for (im=_fin.begin();im!=_fin.end(); im++)
-        {
-#if defined(_DEBUG_) || defined(_DEBUG)
-               const client_infos &lesInfos = *(*im).second ;
-               MESSAGE("Deletion") ; SCRUTE( lesInfos._name ) ;
-#endif
-               _fin.erase ( im ) ;
-       }
-       ASSERT(_fin.size()==0) ;
-       _Compteur = -1 ;
-       if ( _SessionName )
-       {
-#ifndef WIN32
-               delete [] _SessionName ;
-#else
-               delete [] (char*)_SessionName ;
-#endif
-               _SessionName = 0 ;
-       }
-       END_OF("RegistryService::~RegistryService()") ;
+        BEGIN_OF("RegistryService::~RegistryService()") ;
+        map<int,client_infos *>::iterator im;
+        for (im=_reg.begin();im!=_reg.end(); im++)
+          {
+                MESSAGE("Delete _reg item " << im->second->_name) ; 
+                delete im->second;
+          }
+        for (im=_fin.begin();im!=_fin.end(); im++)
+          {
+                MESSAGE("Delete _fin item " << im->second->_name) ; 
+                delete im->second;
+          }
+        _Compteur = -1 ;
+        if ( _SessionName )
+          {
+                delete [] (char*)_SessionName ;
+                _SessionName = 0 ;
+          }
+        END_OF("RegistryService::~RegistryService()") ;
 }
 
 /* ------------------------------*/
-/* Contrats IDL                  */
+/* IDL contracts                 */
 /* ------------------------------*/
 
 CORBA::ULong RegistryService::size ( void )
 {
-       ASSERT(_SessionName) ;
-       ASSERT(strlen(_SessionName)>0) ;
-       return _reg.size() ;
+        ASSERT(_SessionName) ;
+        ASSERT(strlen(_SessionName)>0) ;
+        return _reg.size() ;
 }
 
-
 CORBA::ULong RegistryService::add( const Registry::Infos & infos )
 {
-       BEGIN_OF("RegistryService::add") ;
-       ASSERT(_SessionName) ;
-       ASSERT(strlen(_SessionName)>0) ;
-       client_infos *ptr_Component = new client_infos( infos ) ;
-       ASSERT(ptr_Component) ;
-       SCRUTE(ptr_Component->_name) ;
-
-       _Compteur++;
-       _reg[_Compteur]=ptr_Component;
-
-       END_OF("RegistryService::add") ;
-       return (CORBA::ULong)_Compteur ;
+        BEGIN_OF("RegistryService::add") ;
+        ASSERT(_SessionName) ;
+        ASSERT(strlen(_SessionName)>0) ;
+        client_infos *ptr_Component = new client_infos( infos ) ;
+        ASSERT(ptr_Component) ;
+        SCRUTE(ptr_Component->_name) ;
+
+        _Compteur++;
+        _reg[_Compteur]=ptr_Component;
+
+        END_OF("RegistryService::add") ;
+        return (CORBA::ULong)_Compteur ;
 }
 
-#ifndef WIN32
-void RegistryService::remove( const CORBA::ULong id)
-#else
 void RegistryService::remove( CORBA::ULong id)
-#endif
 {
-       BEGIN_OF("RegistryService::remove") ;
-       SCRUTE(id) ;
-       ASSERT(_SessionName) ;
-       ASSERT(strlen(_SessionName)>0) ;
-       
-       ASSERT(_reg.find(id)!=_reg.end()) 
-       _reg[id]->_status=TERMINATED;
-       _reg[id]->_ts_end = time(NULL) ;
-
-       _fin[id]=_reg[id];
-       SCRUTE(_fin.size()) ;
-
-       map<int,client_infos *>::iterator pos = _reg.find ( id ) ;
-        _reg.erase ( pos ) ;
-       SCRUTE(_reg.size()) ;
-       SCRUTE(_fin.size()) ;
-
-       END_OF("RegistryService::remove") ;
-       return ;
+        BEGIN_OF("RegistryService::remove") ;
+        SCRUTE(id) ;
+        ASSERT(_SessionName) ;
+        ASSERT(strlen(_SessionName)>0) ;
+        
+        ASSERT(_reg.find(id)!=_reg.end()) 
+        _reg[id]->_status=TERMINATED;
+        _reg[id]->_ts_end = time(NULL) ;
+
+        _fin[id]=_reg[id];
+        _reg.erase(id);
+
+        SCRUTE(_reg.size()) ;
+        SCRUTE(_fin.size()) ;
+
+        END_OF("RegistryService::remove") ;
+        return ;
 }
 
 
-#ifndef WIN32
-void RegistryService::hello( const CORBA::ULong id )
-#else
 void RegistryService::hello( CORBA::ULong id )
-#endif
 {
-       BEGIN_OF("RegistryService::hello") ;
-       SCRUTE(id) ;
-       ASSERT(_SessionName) ;
-       ASSERT(strlen(_SessionName)>0) ;
-
-       ASSERT(_reg.find(id)!=_reg.end()) 
-       _reg[id]->_ts_hello = time(NULL) ;
-               
-       END_OF("RegistryService::hello") ;
-       return ;
-}
+        BEGIN_OF("RegistryService::hello") ;
+        SCRUTE(id) ;
+        ASSERT(_SessionName) ;
+        ASSERT(strlen(_SessionName)>0) ;
 
+        ASSERT(_reg.find(id)!=_reg.end()) 
+        _reg[id]->_ts_hello = time(NULL) ;
+                
+        END_OF("RegistryService::hello") ;
+        return ;
+}
 
 void RegistryService::end( void )
 {
-       ASSERT(_SessionName) ;
-       ASSERT(strlen(_SessionName)>0) ;
-       BEGIN_OF( "RegistryService::end( void )" ) ;
-       exit( EXIT_SUCCESS ) ;
+        ASSERT(_SessionName) ;
+        ASSERT(strlen(_SessionName)>0) ;
+        BEGIN_OF( "RegistryService::end( void )" ) ;
+        exit( EXIT_SUCCESS ) ;
 }
 
-
 Registry::AllInfos* RegistryService::getall( void )
 {
-       ASSERT(_SessionName) ;
-       ASSERT(strlen(_SessionName)>0) ;
-       return RegistryService::makeseq(_reg) ;
+        ASSERT(_SessionName) ;
+        ASSERT(strlen(_SessionName)>0) ;
+        return RegistryService::makeseq(_reg) ;
 }
 
 Registry::AllInfos* RegistryService::history( void )
 {
-       ASSERT(_SessionName) ;
-       ASSERT(strlen(_SessionName)>0) ;
-       return RegistryService::makeseq(_fin) ;
+        ASSERT(_SessionName) ;
+        ASSERT(strlen(_SessionName)>0) ;
+        return RegistryService::makeseq(_fin) ;
 }
 
 Registry::AllInfos* RegistryService::makeseq(map<int,client_infos *> &mymap )
 {
-       int i=0 ;
+        int i=0 ;
 
-       Registry::AllInfos *all = new Registry::AllInfos ;
-       ASSERT(all) ;
-       const int RegLength = mymap.size();
-       all->length(RegLength);
+        Registry::AllInfos *all = new Registry::AllInfos ;
+        ASSERT(all) ;
+        const int RegLength = mymap.size();
+        all->length(RegLength);
 
-       map<int,client_infos *>::iterator im;
-       for (im=mymap.begin();im!=mymap.end(); im++)
+        map<int,client_infos *>::iterator im;
+        for (im=mymap.begin();im!=mymap.end(); im++)
         {
 
-               Registry::Infos &infos = (*all)[i] ;
-               const client_infos &lesInfos = *(*im).second ;
-               infos.name      = CORBA::string_dup( lesInfos._name ) ;
-               infos.pid       = lesInfos._pid ;
-               infos.pwname    = lesInfos._pwname ;
-               infos.machine   = CORBA::string_dup( lesInfos._machine ) ;
-               infos.adip      = CORBA::string_dup( lesInfos._adip ) ;
-               infos.uid       = lesInfos._uid ;
-               infos.tc_start  = lesInfos._ts_start + lesInfos._difftime ;
-               infos.tc_hello  = lesInfos._ts_hello + lesInfos._difftime ;
-               infos.tc_end    = lesInfos._ts_end + lesInfos._difftime ;
-               infos.difftime  = lesInfos._difftime ;
-               infos.cdir      = CORBA::string_dup( lesInfos._cdir ) ;
-               infos.status    = lesInfos._status ;
-
-               i++;
-       }
-
-       return all ;
+                Registry::Infos &infos = (*all)[i] ;
+                const client_infos &lesInfos = *(*im).second ;
+                infos.name        = CORBA::string_dup( lesInfos._name ) ;
+                infos.pid        = lesInfos._pid ;
+                infos.pwname        = lesInfos._pwname ;
+                infos.machine        = CORBA::string_dup( lesInfos._machine ) ;
+                infos.adip        = CORBA::string_dup( lesInfos._adip ) ;
+                infos.uid        = lesInfos._uid ;
+                infos.tc_start        = lesInfos._ts_start + lesInfos._difftime ;
+                infos.tc_hello        = lesInfos._ts_hello + lesInfos._difftime ;
+                infos.tc_end        = lesInfos._ts_end + lesInfos._difftime ;
+                infos.difftime        = lesInfos._difftime ;
+                infos.cdir        = CORBA::string_dup( lesInfos._cdir ) ;
+                infos.status        = lesInfos._status ;
+
+                i++;
+        }
+
+        return all ;
 }
 
 
 /* ------------------------------*/
-/* Autres                        */
+/* Others                        */
 /* ------------------------------*/
 
 RegistryService::client_infos::client_infos( const Registry::Infos &infos ):\
-                                                                       _ior(duplicate(infos.ior)),\
-                                                                       _name(duplicate(infos.name)),\
-                                                                       _pid(infos.pid),\
-                                                                       _machine(duplicate(infos.machine)),\
-                                                                       _adip(duplicate(infos.adip)),\
-                                                                       _uid(infos.uid),\
-                                                                       _pwname(duplicate(infos.pwname)),\
-                                                                       _ts_start(time(NULL)),\
-                                                                       _difftime(infos.tc_start - _ts_start),\
-                                                                       _cdir(duplicate(infos.cdir)),\
-                                                                       _ts_hello(_ts_start),\
-                                                                       _ts_end(0),\
-                                                                       _status(RUNNING)
+                                                                        _ior(duplicate(infos.ior)),\
+                                                                        _name(duplicate(infos.name)),\
+                                                                        _pid(infos.pid),\
+                                                                        _machine(duplicate(infos.machine)),\
+                                                                        _adip(duplicate(infos.adip)),\
+                                                                        _uid(infos.uid),\
+                                                                        _pwname(duplicate(infos.pwname)),\
+                                                                        _ts_start(time(NULL)),\
+                                                                        _difftime(infos.tc_start - _ts_start),\
+                                                                        _cdir(duplicate(infos.cdir)),\
+                                                                        _ts_hello(_ts_start),\
+                                                                        _ts_end(0),\
+                                                                        _status(RUNNING)
 {
-  //   SCRUTE(_ior) ;
-       ;
 }
 
 RegistryService::client_infos::~client_infos()
 {
-       delete [] (char*)_ior ; (char*&)_ior = NULL  ;
-       delete [] (char*)_name ; (char*&)_name = NULL  ;
-       delete [] (char*)_machine ; (char*&)_machine = NULL ;
-       delete [] (char*)_pwname ; (char*&)_pwname = NULL ;
-       delete [] (char*)_adip ; (char*&)_adip = NULL ;
-       delete [] (char*)_cdir ; (char*&)_cdir = NULL ;
+        delete [] (char*)_ior ; (char*&)_ior = NULL  ;
+        delete [] (char*)_name ; (char*&)_name = NULL  ;
+        delete [] (char*)_machine ; (char*&)_machine = NULL ;
+        delete [] (char*)_pwname ; (char*&)_pwname = NULL ;
+        delete [] (char*)_adip ; (char*&)_adip = NULL ;
+        delete [] (char*)_cdir ; (char*&)_cdir = NULL ;
 }
 
 void RegistryService::SessionName( const char *sessionName )
 {
-       ASSERT(sessionName) ;
-       ASSERT(strlen(sessionName)>0) ;
-       _SessionName = duplicate(sessionName) ;
-       return ;
+        ASSERT(sessionName) ;
+        ASSERT(strlen(sessionName)>0) ;
+        _SessionName = duplicate(sessionName) ;
+        return ;
 }
 void RegistryService::ping()
 {