From 5a1228b63d79847dc4a19f05bc6f65e079545835 Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 13 Nov 2018 18:59:05 +0300 Subject: [PATCH] Fix crash in GetPathPrefix() method --- .../SALOME_ModuleCatalog_impl.cxx | 56 ++++++++----------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx index 9924f6687..6fd8da5f6 100644 --- a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx +++ b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx @@ -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()) ; } //---------------------------------------------------------------------- -- 2.39.2