From e91811c2ef3ac472afbdb93aefb05a863bfbcc07 Mon Sep 17 00:00:00 2001 From: ptv Date: Fri, 14 Jul 2006 05:53:36 +0000 Subject: [PATCH] remove memory leaks uninitalised memory read, etc... noticed with Rational Purify on Windows --- src/SMESHGUI/SMESHGUI.cxx | 2 +- src/SMESH_I/SMESH_Filter_i.cxx | 43 ------------------------ src/SMESH_I/SMESH_Gen_i.cxx | 53 +++++++++++++++++------------- src/SMESH_I/SMESH_Gen_i_1.cxx | 9 +++-- src/SMESH_I/SMESH_Hypothesis_i.cxx | 15 --------- src/SMESH_I/SMESH_Hypothesis_i.hxx | 7 ---- src/SMESH_I/SMESH_MEDMesh_i.cxx | 4 +-- src/SMESH_I/SMESH_Mesh_i.cxx | 1 - src/SMESH_I/SMESH_subMesh_i.cxx | 1 - 9 files changed, 39 insertions(+), 96 deletions(-) diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index 809a98b2a..2581f8faa 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -2788,7 +2788,7 @@ QString SMESHGUI::engineIOR() const { CORBA::ORB_var anORB = getApp()->orb(); CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen()); - return anIOR.in(); + return QString( anIOR.in() ); } void SMESHGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ ) diff --git a/src/SMESH_I/SMESH_Filter_i.cxx b/src/SMESH_I/SMESH_Filter_i.cxx index 0b0b72ed2..4d3c2dc9c 100644 --- a/src/SMESH_I/SMESH_Filter_i.cxx +++ b/src/SMESH_I/SMESH_Filter_i.cxx @@ -452,11 +452,6 @@ static char* getShapeNameByID ( const char* theID ) Functor_i::Functor_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() ) { - // registration moved from constructor of abstract class - // to each ::Create* (creation of specific fucntor instance) - // to register fully declared this instance. - //PortableServer::ObjectId_var anObjectId = - // SMESH_Gen_i::GetPOA()->activate_object( this ); } Functor_i::~Functor_i() @@ -1420,11 +1415,6 @@ FunctorType LogicalOR_i::GetFunctorType() FilterManager_i::FilterManager_i() : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() ) { - // registration moved from constructor of abstract class - // to each ::Create* (creation of specific fucntor instance) - // to register fully declared this instance. - //PortableServer::ObjectId_var anObjectId = - // SMESH_Gen_i::GetPOA()->activate_object( this ); } @@ -1437,7 +1427,6 @@ FilterManager_i::~FilterManager_i() MinimumAngle_ptr FilterManager_i::CreateMinimumAngle() { SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i(); - SMESH_Gen_i::GetPOA()->activate_object( aServant ); SMESH::MinimumAngle_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::AspectRatio_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::AspectRatio3D_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::Warping_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::Taper_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::Skew_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::Area_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::Volume3D_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::Length_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::Length2D_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::MultiConnection_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::MultiConnection2D_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::BelongToGeom_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::BelongToPlane_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::BelongToCylinder_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::LyingOnGeom_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::FreeBorders_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::FreeEdges_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::RangeOfIds_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::BadOrientedVolume_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::LessThan_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::MoreThan_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::EqualTo_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::LogicalNOT_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::LogicalAND_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::LogicalOR_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::Filter_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::FilterLibrary_var anObj = aServant->_this(); TPythonDump()<activate_object( aServant ); SMESH::FilterLibrary_var anObj = aServant->_this(); TPythonDump()<activate_object( aFilter ); SMESH::FilterManager_var anObj = aFilter->_this(); return anObj._retn(); } @@ -2023,7 +1983,6 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria myPredicate->Destroy(); SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i(); - SMESH_Gen_i::GetPOA()->activate_object( aFilter ); FilterManager_ptr aFilterMgr = aFilter->_this(); // CREATE two lists ( PREDICATES and LOG OP ) @@ -2575,7 +2534,6 @@ FilterLibrary_i::FilterLibrary_i( const char* theFileName ) { myFileName = strdup( theFileName ); SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i(); - SMESH_Gen_i::GetPOA()->activate_object( aFilterMgr ); myFilterMgr = aFilterMgr->_this(); LDOMParser aParser; @@ -2608,7 +2566,6 @@ FilterLibrary_i::FilterLibrary_i() { myFileName = 0; SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i(); - SMESH_Gen_i::GetPOA()->activate_object( aFilter ); myFilterMgr = aFilter->_this(); myDoc = LDOM_Document::createDocument( LDOMString() ); diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index 8a3a5fb27..185e2fc68 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -384,8 +384,6 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName); myHypothesis_i = myHypCreatorMap[string(theHypName)]->Create (myPoa, GetCurrentStudyID(), &myGen); - // _CS_gbo Explicit activation (no longer made in the constructor). - myHypothesis_i->Activate(); myHypothesis_i->SetLibName(aPlatformLibName/*theLibName*/); // for persistency assurance } catch (SALOME_Exception& S_ex) @@ -1302,7 +1300,8 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, if ( myImpl ) { string hypname = string( myHyp->GetName() ); string libname = string( myHyp->GetLibName() ); - int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) ); + CORBA::String_var objStr = GetORB()->object_to_string( anObject ); + int id = myStudyContext->findId( string( objStr.in() ) ); string hypdata = string( myImpl->SaveTo() ); // for each hypothesis create HDF group basing on its id @@ -1355,7 +1354,8 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, if ( myImpl ) { string hypname = string( myHyp->GetName() ); string libname = string( myHyp->GetLibName() ); - int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) ); + CORBA::String_var objStr = GetORB()->object_to_string( anObject ); + int id = myStudyContext->findId( string( objStr.in() ) ); string hypdata = string( myImpl->SaveTo() ); // for each algorithm create HDF group basing on its id @@ -1398,7 +1398,8 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, if ( !myMesh->_is_nil() ) { SMESH_Mesh_i* myImpl = dynamic_cast( GetServant( myMesh ).in() ); if ( myImpl ) { - int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) ); + CORBA::String_var objStr = GetORB()->object_to_string( anObject ); + int id = myStudyContext->findId( string( objStr.in() ) ); ::SMESH_Mesh& myLocMesh = myImpl->GetImpl(); SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS(); @@ -1467,7 +1468,8 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, //string myRefOnObject = myRefOnHyp->GetID(); CORBA::Object_var anObject = SObjectToObject( myRefOnHyp ); - int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) ); + CORBA::String_var objStr = GetORB()->object_to_string( anObject ); + int id = myStudyContext->findId( string( objStr.in() ) ); //if ( myRefOnObject.length() > 0 ) { //aSize[ 0 ] = myRefOnObject.length() + 1; char hypName[ 30 ], hypId[ 30 ]; @@ -1509,7 +1511,8 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, //string myRefOnObject = myRefOnAlgo->GetID(); CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo ); - int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) ); + CORBA::String_var objStr = GetORB()->object_to_string( anObject ); + int id = myStudyContext->findId( string( objStr.in() ) ); //if ( myRefOnObject.length() > 0 ) { //aSize[ 0 ] = myRefOnObject.length() + 1; char algoName[ 30 ], algoId[ 30 ]; @@ -1599,7 +1602,8 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, if ( !CORBA::is_nil( anSubObject )) { SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ; - int subid = myStudyContext->findId( string( GetORB()->object_to_string( anSubObject ) ) ); + CORBA::String_var objStr = GetORB()->object_to_string( anSubObject ); + int subid = myStudyContext->findId( string( objStr.in() ) ); // for each mesh open the HDF group basing on its id char submeshGrpName[ 30 ]; @@ -1636,7 +1640,8 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, if ( ok ) { //string myRefOnObject = myRefOnHyp->GetID(); CORBA::Object_var anObject = SObjectToObject( myRefOnHyp ); - int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) ); + CORBA::String_var objStr = GetORB()->object_to_string( anObject ); + int id = myStudyContext->findId( string( objStr.in() ) ); //if ( myRefOnObject.length() > 0 ) { //aSize[ 0 ] = myRefOnObject.length() + 1; char hypName[ 30 ], hypId[ 30 ]; @@ -1670,7 +1675,8 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, if ( ok ) { //string myRefOnObject = myRefOnAlgo->GetID(); CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo ); - int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) ); + CORBA::String_var objStr = GetORB()->object_to_string( anObject ); + int id = myStudyContext->findId( string( objStr.in() ) ); //if ( myRefOnObject.length() > 0 ) { //aSize[ 0 ] = myRefOnObject.length() + 1; char algoName[ 30 ], algoId[ 30 ]; @@ -1727,7 +1733,8 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, if ( !myGroupImpl ) continue; - int anId = myStudyContext->findId( string( GetORB()->object_to_string( aSubObject ) ) ); + CORBA::String_var objStr = GetORB()->object_to_string( aSubObject ); + int anId = myStudyContext->findId( string( objStr.in() ) ); // For each group, create a dataset named "Group " // and store the group's user name into it @@ -2148,8 +2155,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, SMESH_Hypothesis_i* myImpl = dynamic_cast( GetServant( myHyp ).in() ); if ( myImpl ) { myImpl->LoadFrom( hypdata.c_str() ); - string iorString = GetORB()->object_to_string( myHyp ); - int newId = myStudyContext->findId( iorString ); + CORBA::String_var iorString = GetORB()->object_to_string( myHyp ); + int newId = myStudyContext->findId( string( iorString.in() ) ); myStudyContext->mapOldToNew( id, newId ); } else @@ -2246,8 +2253,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, SMESH_Hypothesis_i* myImpl = dynamic_cast( GetServant( myHyp ).in() ); if ( myImpl ) { myImpl->LoadFrom( hypdata.c_str() ); - string iorString = GetORB()->object_to_string( myHyp ); - int newId = myStudyContext->findId( iorString ); + CORBA::String_var iorString = GetORB()->object_to_string( myHyp ); + int newId = myStudyContext->findId( string( iorString.in() ) ); myStudyContext->mapOldToNew( id, newId ); } else @@ -2286,8 +2293,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, SMESH_Mesh_i* myNewMeshImpl = dynamic_cast( GetServant( myNewMesh ).in() ); if ( !myNewMeshImpl ) continue; - string iorString = GetORB()->object_to_string( myNewMesh ); - int newId = myStudyContext->findId( iorString ); + CORBA::String_var iorString = GetORB()->object_to_string( myNewMesh ); + int newId = myStudyContext->findId( string( iorString.in() ) ); myStudyContext->mapOldToNew( id, newId ); ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl(); @@ -2472,8 +2479,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, ( myNewMeshImpl->createSubMesh( aSubShapeObject ) ); if ( aSubMesh->_is_nil() ) continue; - string iorSubString = GetORB()->object_to_string( aSubMesh ); - int newSubId = myStudyContext->findId( iorSubString ); + CORBA::String_var iorSubString = GetORB()->object_to_string( aSubMesh ); + int newSubId = myStudyContext->findId( string( iorSubString.in() ) ); myStudyContext->mapOldToNew( subid, newSubId ); } } @@ -2770,8 +2777,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, if ( aNewGroup->_is_nil() ) continue; - string iorSubString = GetORB()->object_to_string( aNewGroup ); - int newSubId = myStudyContext->findId( iorSubString ); + CORBA::String_var iorSubString = GetORB()->object_to_string( aNewGroup ); + int newSubId = myStudyContext->findId( string( iorSubString.in() ) ); myStudyContext->mapOldToNew( subid, newSubId ); SMESH_GroupBase_i* aGroupImpl = @@ -2925,8 +2932,8 @@ int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject) { StudyContext* myStudyContext = GetCurrentStudyContext(); if ( myStudyContext && !CORBA::is_nil( theObject )) { - string iorString = GetORB()->object_to_string( theObject ); - return myStudyContext->addObject( iorString ); + CORBA::String_var iorString = GetORB()->object_to_string( theObject ); + return myStudyContext->addObject( string( iorString.in() ) ); } return 0; } diff --git a/src/SMESH_I/SMESH_Gen_i_1.cxx b/src/SMESH_I/SMESH_Gen_i_1.cxx index 2021f22e2..2ff4d8874 100644 --- a/src/SMESH_I/SMESH_Gen_i_1.cxx +++ b/src/SMESH_I/SMESH_Gen_i_1.cxx @@ -180,7 +180,10 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(SALOMEDS::Study_ptr theStudy, { SALOMEDS::SObject_var aSO; if ( !CORBA::is_nil( theStudy ) && !CORBA::is_nil( theObject )) - aSO = theStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string( theObject ) ); + { + CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theObject ); + aSO = theStudy->FindObjectIOR( objStr.in() ); + } return aSO._retn(); } @@ -253,8 +256,8 @@ static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr theStudy, SALOMEDS::GenericAttribute_var anAttr; if ( !CORBA::is_nil( theIOR )) { anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" ); - SALOMEDS::AttributeIOR::_narrow(anAttr)->SetValue - ( SMESH_Gen_i::GetORB()->object_to_string( theIOR ) ); + CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theIOR ); + SALOMEDS::AttributeIOR::_narrow(anAttr)->SetValue( objStr.in() ); } if ( thePixMap ) { anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" ); diff --git a/src/SMESH_I/SMESH_Hypothesis_i.cxx b/src/SMESH_I/SMESH_Hypothesis_i.cxx index 1ece6c6f1..fedc07722 100644 --- a/src/SMESH_I/SMESH_Hypothesis_i.cxx +++ b/src/SMESH_I/SMESH_Hypothesis_i.cxx @@ -46,25 +46,10 @@ SMESH_Hypothesis_i::SMESH_Hypothesis_i( PortableServer::POA_ptr thePOA ) { MESSAGE( "SMESH_Hypothesis_i::SMESH_Hypothesis_i / Début" ); myBaseImpl = 0; - // _CS_gbo This instruction fails - // thePOA->activate_object( this ); - // _CS_gbo I keep the POA reference to activate the object in the future. - myPOA = thePOA; MESSAGE( "SMESH_Hypothesis_i::SMESH_Hypothesis_i / Fin" ); }; -//============================================================================= -/*! - * SMESH_Hypothesis_i::Activate() - * - * Activation of the object - */ -//============================================================================= -void SMESH_Hypothesis_i::Activate() { - myPOA->activate_object( this ); -} - //============================================================================= /*! * SMESH_Hypothesis_i::~SMESH_Hypothesis_i diff --git a/src/SMESH_I/SMESH_Hypothesis_i.hxx b/src/SMESH_I/SMESH_Hypothesis_i.hxx index fed1426c2..634e245c6 100644 --- a/src/SMESH_I/SMESH_Hypothesis_i.hxx +++ b/src/SMESH_I/SMESH_Hypothesis_i.hxx @@ -69,19 +69,12 @@ public: // Get implementation ::SMESH_Hypothesis* GetImpl(); - // _CS_gbo_ Activate the object using the POA - void Activate(); - // Persistence virtual char* SaveTo(); virtual void LoadFrom( const char* theStream ); protected: ::SMESH_Hypothesis* myBaseImpl; // base hypothesis implementation - - // _CS_gbo_070505 To keep the reference and delayed the activation - // in the methode Activate(). - PortableServer::POA_ptr myPOA; }; // ====================================================== diff --git a/src/SMESH_I/SMESH_MEDMesh_i.cxx b/src/SMESH_I/SMESH_MEDMesh_i.cxx index 3840b27fa..b7f15cf17 100644 --- a/src/SMESH_I/SMESH_MEDMesh_i.cxx +++ b/src/SMESH_I/SMESH_MEDMesh_i.cxx @@ -863,8 +863,8 @@ void SMESH_MEDMesh_i::addInStudy(SALOMEDS::Study_ptr myStudy, * ORB_INIT &init = *SINGLETON_::Instance() ; * ASSERT(SINGLETON_::IsAlreadyExisting()) ; * CORBA::ORB_var &orb = init(0,0); - * string iorStr = orb->object_to_string(myIor); - * //myBuilder->AddAttribute(newObj,SALOMEDS::IOR,iorStr.c_str()); + * CORBA::String_var iorStr = orb->object_to_string(myIor); + * //myBuilder->AddAttribute(newObj,SALOMEDS::IOR,iorStr.in()); * SALOMEDS::AttributeIOR_var aIOR = SALOMEDS::AttributeIOR::_narrow( * myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR")); * aIOR->SetValue(iorStr.c_str()); diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index 367eda450..f6896eaf1 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -94,7 +94,6 @@ SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA, _gen_i = gen_i; _id = myIdGenerator++; _studyId = studyId; - thePOA->activate_object( this ); } //============================================================================= diff --git a/src/SMESH_I/SMESH_subMesh_i.cxx b/src/SMESH_I/SMESH_subMesh_i.cxx index d8f5c2bb8..a073dfd7a 100644 --- a/src/SMESH_I/SMESH_subMesh_i.cxx +++ b/src/SMESH_I/SMESH_subMesh_i.cxx @@ -70,7 +70,6 @@ SMESH_subMesh_i::SMESH_subMesh_i( PortableServer::POA_ptr thePOA, _gen_i = gen_i; _mesh_i = mesh_i; _localId = localId; - thePOA->activate_object( this ); // **** } //============================================================================= -- 2.39.2