]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
remove memory leaks uninitalised memory read, etc...
authorptv <ptv@opencascade.com>
Fri, 14 Jul 2006 05:40:03 +0000 (05:40 +0000)
committerptv <ptv@opencascade.com>
Fri, 14 Jul 2006 05:40:03 +0000 (05:40 +0000)
noticed with Rational Purify on Windows

src/NamingService/NamingService_WaitForServerReadiness.cxx
src/NamingService/SALOME_NamingService.cxx
src/SALOMEDS/SALOMEDS_AttributeIOR_i.cxx
src/SALOMEDS/SALOMEDS_Study.cxx
src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx
src/SALOMEDS/SALOMEDS_StudyManager_i.cxx
src/SALOMEDS/SALOMEDS_Study_i.cxx
src/Utils/Utils_Identity.cxx

index 308e104b0bfd58354a332a5d571dce9b4796f00a..6d9d1f962f110b453d4e5f76b279326086c971f9 100644 (file)
@@ -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;
index a7768ec2adec35536ae5fc64ed61fbd10b4fcdb0..61351cfec14da62817f2f780002b1218ccab81a0 100644 (file)
@@ -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));
         }
     }
 
index 362308d7a71718f1675595c4955e734c9d0bedf1..e1d058fc0fbbe0491785e2a5f17d09e4f49197e9 100644 (file)
@@ -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);
 }
index 2c99122fb11b6fb93a8de01cc43b3b339a15d2ab..2f4c6d9361a1bd27951a7381b0ae939118638af1 100644 (file)
@@ -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) 
index 87adc2db8318010693d725c58538b605ede86c72..6306b9858460e16fcb3d67980beb6ad702ab6d9a 100644 (file)
@@ -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());
 }
 
 //============================================================================
index 617f7c19426eb3c05fbe546d33214d8eb07d66fe..bd5761d320d27b5a8e9de0bd0c74e137b93f8a58 100644 (file)
@@ -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
index b36531420076f9da2bcf559004abcb31fcb631d3..c6f32cc84e02679e1ff8c08fff0f77821ab67573 100644 (file)
@@ -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());
index 5fc40ae1aac3bc56cade1289db0bb4608cedf5cc..48694e8a9c25ab4313515c148f022861fa3b1fb3 100644 (file)
@@ -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 ;
+
 }
 
 /*------------*/