]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Fix crash in GetPathPrefix() method
authorvsr <vsr@opencascade.com>
Tue, 13 Nov 2018 15:59:05 +0000 (18:59 +0300)
committervsr <vsr@opencascade.com>
Tue, 13 Nov 2018 15:59:05 +0000 (18:59 +0300)
src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx

index 9924f6687c304acafaa6060ef54f543ea70674d6..6fd8da5f63080a768ea8e03987d0e58f5f26d7a8 100644 (file)
@@ -390,51 +390,43 @@ SALOME_ModuleCatalogImpl::GetComputerList()
 // Function : GetPathPrefix
 // Purpose  : get the PathPrefix of a computer
 //----------------------------------------------------------------------
-char 
+char* 
 SALOME_ModuleCatalogImpl::GetPathPrefix(const char* machinename) {
   if(MYDEBUG) MESSAGE("Begin of GetPathPrefix");
   // Variables initialisation
-  char* _path = NULL;
-  bool _find = false ;
+  std::string _path;
+  bool _find = false;
 
   // Parse all the path prefixes
   // looking for the wanted computer
-  for (unsigned int ind = 0 ; ind < myPrivate->_personal_path_list.size() ; ind++)
+  for (unsigned int ind = 0; ind < myPrivate->_personal_path_list.size() && !_find; ind++)
+  {
+    for (unsigned int ind1 = 0; ind1 < myPrivate->_personal_path_list[ind].listOfComputer.size() && !_find; ind1++)
     {
-      for (unsigned int ind1 = 0 ; ind1 < myPrivate->_personal_path_list[ind].listOfComputer.size() ; ind1++)    
-        {
-          if (strcmp(machinename, myPrivate->_personal_path_list[ind].listOfComputer[ind1].c_str()) == 0)
-            {
-              _find = true ;
-              // Wanted computer
-              // affect the path to be returned
-                const char* _temp = myPrivate->_personal_path_list[ind].path.c_str() ;
-                  _path = new char[strlen(_temp)+1];
-              strcpy(_path,_temp);
-            }
-        }
+      if ( myPrivate->_personal_path_list[ind].listOfComputer[ind1] == machinename )
+      {
+        _find = true;
+        // Wanted computer
+        // affect the path to be returned
+        _path = myPrivate->_personal_path_list[ind].path;
+      }
     }
+  }
 
-  if (!_find)
+  for (unsigned int ind = 0; ind < myPrivate->_general_path_list.size() && !_find; ind++)
+  {
+    for (unsigned int ind1 = 0; ind1 < myPrivate->_general_path_list[ind].listOfComputer.size() && !_find; ind1++)
     {
-    for (unsigned int ind = 0 ; ind < myPrivate->_general_path_list.size() ; ind++)
+      if (myPrivate->_general_path_list[ind].listOfComputer[ind1] == machinename)
       {
-        for (unsigned int ind1 = 0 ; ind1 < myPrivate->_general_path_list[ind].listOfComputer.size() ; ind1++)    
-          {
-            if (strcmp(machinename, myPrivate->_general_path_list[ind].listOfComputer[ind1].c_str()) == 0)
-              {
-                _find = true ;
-                // Wanted computer
-                // affect the path to be returned
-                  const char* _temp = myPrivate->_general_path_list[ind].path.c_str() ;
-                    _path = new char[strlen(_temp)+1];
-                strcpy(_path,_temp);
-              }
-          }
+        _find = true;
+        // Wanted computer
+        // affect the path to be returned
+        _path = myPrivate->_general_path_list[ind].path;
       }
     }
-
-  return _path;
+  }
+  return CORBA::string_dup(_path.c_str()) ;
 }
 
 //----------------------------------------------------------------------