From 94f7c40e82aa47047cfdaecfcf5c0112eb97f21c Mon Sep 17 00:00:00 2001 From: ptv Date: Fri, 14 Jul 2006 05:43:55 +0000 Subject: [PATCH] remove memory leaks uninitalised memory read, etc... noticed with Rational Purify on Windows --- .../SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx | 8 +++++-- src/SalomeApp/SalomeApp_Application.cxx | 5 ++++- src/Session/Session_ServerLauncher.cxx | 6 +++-- src/Session/Session_ServerThread.cxx | 22 ++++++++++++++----- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx index d2f73a653..8ea7457cb 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx @@ -825,9 +825,13 @@ Engines::Component_var SALOME_PYQT_Module::getEngine() const */ QString SALOME_PYQT_Module::engineIOR() const { + QString anIOR = QString::null; if ( !CORBA::is_nil( getEngine() ) ) - return QString( getApp()->orb()->object_to_string( getEngine() ) ); - return QString( "" ); + { + CORBA::String_var objStr = getApp()->orb()->object_to_string( getEngine() ); + anIOR = QString( objStr.in() ); + } + return anIOR; } /*! diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 5e73de8a6..1f2f5eb90 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -742,7 +742,10 @@ QString SalomeApp_Application::defaultEngineIOR() QString anIOR( "" ); CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" ); if ( !CORBA::is_nil( anEngine ) ) - anIOR = orb()->object_to_string( anEngine ); + { + CORBA::String_var objStr = orb()->object_to_string( anEngine ); + anIOR = QString( objStr.in() ); + } return anIOR; } diff --git a/src/Session/Session_ServerLauncher.cxx b/src/Session/Session_ServerLauncher.cxx index d4b055416..0604c7731 100755 --- a/src/Session/Session_ServerLauncher.cxx +++ b/src/Session/Session_ServerLauncher.cxx @@ -190,7 +190,7 @@ void Session_ServerLauncher::ActivateAll() { for (int i=0; iInit(); + free( argv[0] ); + delete[] argv; } // Always launch Session Server @@ -211,8 +213,8 @@ void Session_ServerLauncher::ActivateAll() Session_SessionThread* aServerThread = new Session_SessionThread(argc, argv, _orb,_root_poa,_SessionMutex,_SessionStarted); _serverThreads.push_front(aServerThread); - aServerThread->Init(); + delete[] argv; } /*! diff --git a/src/Session/Session_ServerThread.cxx b/src/Session/Session_ServerThread.cxx index d9ef4f806..1407cf4a2 100755 --- a/src/Session/Session_ServerThread.cxx +++ b/src/Session/Session_ServerThread.cxx @@ -80,7 +80,11 @@ Session_ServerThread::Session_ServerThread(int argc, { //MESSAGE("Session_ServerThread Constructor " << argv[0]); _argc = argc; - _argv = argv; + _argv = new char*[ _argc + 1 ]; + _argv[_argc] = 0; + for (int i = 0; i < _argc; i++ ) + _argv[i] = strdup( argv[i] ); + _orb = CORBA::ORB::_duplicate(orb); _root_poa = PortableServer::POA::_duplicate(poa); _servType =-1; @@ -94,6 +98,10 @@ Session_ServerThread::Session_ServerThread(int argc, Session_ServerThread::~Session_ServerThread() { //MESSAGE("~Session_ServerThread "<< _argv[0]); + delete _NS; + for (int i = 0; i <_argc ; i++ ) + free( _argv[i] ); + delete[] _argv; } /*! @@ -283,10 +291,10 @@ void Session_ServerThread::ActivateRegistry(int argc, INFOS("RegistryService servant already existing" ); ASSERT(0); } - catch( const ServiceUnreachable &ex ) + catch( const ServiceUnreachable &/*ex*/ ) { } - catch( const CORBA::Exception &exx ) + catch( const CORBA::Exception &/*exx*/ ) { } string absoluteName = string("/") + registryName; @@ -422,10 +430,14 @@ void Session_ServerThread::ActivateEngine(int /*argc*/, char ** /*argv*/) { INFOS("SalomeApp_Engine thread started"); SalomeApp_Engine_i* anEngine = new SalomeApp_Engine_i(); - /*PortableServer::ObjectId_var id = */_root_poa->activate_object( anEngine ); + // declare variable and get value for them to avoid compilation warning of unused variable + // this variable is necessary to avoid memory leak of memory allocated in corba + PortableServer::ObjectId_var id = 0; + id = _root_poa->activate_object( anEngine ); + ///*PortableServer::ObjectId_var id = */_root_poa->activate_object( anEngine ); INFOS("poa->activate_object( SalomeApp_Engine )"); - CORBA::Object_ptr obj = anEngine->_this(); + CORBA::Object_var obj = anEngine->_this(); _NS->Register( obj ,"/SalomeAppEngine"); } -- 2.39.2