From: ptv Date: Fri, 14 Jul 2006 05:40:03 +0000 (+0000) Subject: remove memory leaks uninitalised memory read, etc... X-Git-Tag: LAST_STABLE_VERSION_21_09_2006_ON_3_2_0~21 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c75d6ce7e7ce1a976e84bd52c14ad14026d93a93;p=modules%2Fkernel.git remove memory leaks uninitalised memory read, etc... noticed with Rational Purify on Windows --- diff --git a/src/NamingService/NamingService_WaitForServerReadiness.cxx b/src/NamingService/NamingService_WaitForServerReadiness.cxx index 308e104b0..6d9d1f962 100644 --- a/src/NamingService/NamingService_WaitForServerReadiness.cxx +++ b/src/NamingService/NamingService_WaitForServerReadiness.cxx @@ -72,7 +72,7 @@ void NamingService_WaitForServerReadiness(SALOME_NamingService* NS, } else { - CORBA::Object_ptr obj = NS->Resolve(serverName.c_str()); + CORBA::Object_var obj = NS->Resolve(serverName.c_str()); if (! CORBA::is_nil(obj)) { found =1; diff --git a/src/NamingService/SALOME_NamingService.cxx b/src/NamingService/SALOME_NamingService.cxx index a7768ec2a..61351cfec 100644 --- a/src/NamingService/SALOME_NamingService.cxx +++ b/src/NamingService/SALOME_NamingService.cxx @@ -368,7 +368,7 @@ CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path) ASSERT(!CORBA::is_nil(_current_context)); - CORBA::Object_ptr obj = CORBA::Object::_nil(); + CORBA::Object_var obj = CORBA::Object::_nil(); try { @@ -411,7 +411,7 @@ CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path) throw ServiceUnreachable(); } - return obj; + return obj._retn(); } // ============================================================================ @@ -449,7 +449,7 @@ CORBA::Object_ptr SALOME_NamingService::ResolveFirst(const char* Path) } // SCRUTE(name); - CORBA::Object_ptr obj = CORBA::Object::_nil(); + CORBA::Object_var obj = CORBA::Object::_nil(); bool isOk = false; if (basePath.empty()) @@ -475,7 +475,7 @@ CORBA::Object_ptr SALOME_NamingService::ResolveFirst(const char* Path) } } - return obj; + return obj._retn(); } // ============================================================================ @@ -1034,7 +1034,9 @@ throw(ServiceUnreachable) if (binding->binding_type == CosNaming::nobject) { - dirList.push_back(CORBA::string_dup(bindingName[0].id)); + // remove memory leak + // dirList.push_back(CORBA::string_dup(bindingName[0].id)); + dirList.push_back(string(bindingName[0].id)); } } diff --git a/src/SALOMEDS/SALOMEDS_AttributeIOR_i.cxx b/src/SALOMEDS/SALOMEDS_AttributeIOR_i.cxx index 362308d7a..e1d058fc0 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeIOR_i.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeIOR_i.cxx @@ -41,5 +41,6 @@ void SALOMEDS_AttributeIOR_i::SetValue(const char* value) SALOMEDS::Locker lock; CheckLocked(); CORBA::String_var Str = CORBA::string_dup(value); - Handle(SALOMEDSImpl_AttributeIOR)::DownCast(_impl)->SetValue(TCollection_ExtendedString(Str)); + TCollection_ExtendedString anExtStr((char *)Str.in()); + Handle(SALOMEDSImpl_AttributeIOR)::DownCast(_impl)->SetValue(anExtStr); } diff --git a/src/SALOMEDS/SALOMEDS_Study.cxx b/src/SALOMEDS/SALOMEDS_Study.cxx index 2c99122fb..2f4c6d936 100644 --- a/src/SALOMEDS/SALOMEDS_Study.cxx +++ b/src/SALOMEDS/SALOMEDS_Study.cxx @@ -645,7 +645,8 @@ bool SALOMEDS_Study::DumpStudy(const string& thePath, const string& theBaseName, std::string SALOMEDS_Study::ConvertObjectToIOR(CORBA::Object_ptr theObject) { - return _orb->object_to_string(theObject); + CORBA::String_var objStr = _orb->object_to_string(theObject); + return string( objStr.in() ); } CORBA::Object_ptr SALOMEDS_Study::ConvertIORToObject(const std::string& theIOR) diff --git a/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx b/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx index 87adc2db8..6306b9858 100644 --- a/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx +++ b/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx @@ -98,7 +98,7 @@ void SALOMEDS_StudyBuilder_i::DefineComponentInstance(SALOMEDS::SComponent_ptr a aSCO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSComponent((char*)aComponent->GetID()); CORBA::String_var iorstr = _orb->object_to_string(IOR); - _impl->DefineComponentInstance(aSCO, (char*)iorstr); + _impl->DefineComponentInstance(aSCO, (char*)iorstr.in()); } //============================================================================ diff --git a/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx b/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx index 617f7c194..bd5761d32 100644 --- a/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx +++ b/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx @@ -134,9 +134,9 @@ SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::NewStudy(const char* study_name) _name_service->Register(Study, study_name); // Assign the value of the IOR in the study->root - const char* IORStudy = _orb->object_to_string(Study); + CORBA::String_var IORStudy = _orb->object_to_string(Study); - aStudyImpl->SetTransientReference((char*)IORStudy); + aStudyImpl->SetTransientReference((char*)IORStudy.in()); _mapOfPOA[Study->StudyId()] = _poa; @@ -166,7 +166,7 @@ SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::Open(const char* aUrl) // Assign the value of the IOR in the study->root CORBA::String_var IORStudy = _orb->object_to_string(Study); - aStudyImpl->SetTransientReference((char*)IORStudy); + aStudyImpl->SetTransientReference((char*)IORStudy.in()); // Register study in the naming service // Path to acces the study diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index b36531420..c6f32cc84 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -275,7 +275,9 @@ char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject) aSO = _impl->FindObjectID(aSObj->GetID()); } else { - aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject)); + CORBA::String_var objStr = _orb->object_to_string(theObject); + TCollection_AsciiString anAscii((char *)objStr.in()); + aSO = _impl->FindObjectIOR(anAscii); } if(aSO.IsNull()) return CORBA::string_dup(aPath.ToCString()); diff --git a/src/Utils/Utils_Identity.cxx b/src/Utils/Utils_Identity.cxx index 5fc40ae1a..48694e8a9 100644 --- a/src/Utils/Utils_Identity.cxx +++ b/src/Utils/Utils_Identity.cxx @@ -83,12 +83,11 @@ const char* duplicate( const char *const str ) ; const char* get_uname( void ) { - char* hostName = new char[MAX_COMPUTERNAME_LENGTH + 1]; - DWORD nSize = MAX_COMPUTERNAME_LENGTH; - // initialisaton - hostName[0]='\0'; - ASSERT(GetComputerName(hostName, &nSize)); - return hostName; + static std::string hostName(MAX_COMPUTERNAME_LENGTH + 1, 0); + static DWORD nSize = hostName.length() + 1; + static int res = GetComputerName(&hostName[0], &nSize); + ASSERT( res ); + return hostName.c_str(); } const char* get_adip( void ) @@ -98,12 +97,11 @@ const char* get_adip( void ) const char* const get_pwname( void ) { - DWORD dwSize = 256 + 1; - char* retVal = new char[256]; - // initialisaton - retVal[0]='\0'; - ASSERT(GetUserName` ( retVal, &dwSize )); - return retVal; + static std::string retVal(256, 0); + static DWORD dwSize = retVal.length() + 1; + static int res = GetUserName( &retVal[0], &dwSize ); + ASSERT( res ); + return retVal.c_str(); } PSID getuid() { @@ -153,9 +151,14 @@ Identity::~Identity(void) //delete [] (char*)_dir ; //(char*&)_dir = NULL ; free((char*)_dir); - +#ifndef WIN32 + // free the memory only on Unix + // becasue at Windows it is the same static variable + // (function get_adip() returns the same char* as get_uname() ) delete [] (char*)_adip ; +#endif (char*&)_adip = NULL ; + } /*------------*/