From: eap Date: Mon, 22 Jul 2013 14:42:25 +0000 (+0000) Subject: Avoid leaks of CORBA objects at calling TPythonDump() << _this() X-Git-Tag: V7_3_0a1~261 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c9d7623239eb8faf10699155d20058f7978f2c63;p=modules%2Fsmesh.git Avoid leaks of CORBA objects at calling TPythonDump() << _this() --- diff --git a/src/SMESH_I/SMESH_Group_i.cxx b/src/SMESH_I/SMESH_Group_i.cxx index d5c06b37c..76dae4673 100644 --- a/src/SMESH_I/SMESH_Group_i.cxx +++ b/src/SMESH_I/SMESH_Group_i.cxx @@ -101,10 +101,6 @@ SMESH_GroupOnFilter_i::SMESH_GroupOnFilter_i( PortableServer::POA_ptr thePOA, SMESH_GroupBase_i::~SMESH_GroupBase_i() { - MESSAGE("~SMESH_GroupBase_i; this = "<removeGroup(myLocalID); - if ( myPreMeshInfo ) delete myPreMeshInfo; myPreMeshInfo = NULL; } @@ -156,15 +152,16 @@ void SMESH_GroupBase_i::SetName( const char* theName ) aGroup->SetName(theName); // Update group name in a study - SMESH_Gen_i* aGen = myMeshServant->GetGen(); - SALOMEDS::Study_var aStudy = aGen->GetCurrentStudy(); - SALOMEDS::SObject_var anSO = aGen->ObjectToSObject( aStudy, _this() ); + SMESH_Gen_i* aGen = myMeshServant->GetGen(); + SALOMEDS::Study_var aStudy = aGen->GetCurrentStudy(); + SMESH::SMESH_GroupBase_var aGrp = _this(); + SALOMEDS::SObject_var anSO = aGen->ObjectToSObject( aStudy, aGrp ); if ( !anSO->_is_nil() ) { aGen->SetName( anSO, theName ); // Update Python script - TPythonDump() << _this() << ".SetName( '" << theName << "' )"; + TPythonDump() << anSO << ".SetName( '" << theName << "' )"; } } @@ -259,7 +256,7 @@ void SMESH_Group_i::Clear() myPreMeshInfo->FullLoadFromFile(); // Update Python script - TPythonDump() << _this() << ".Clear()"; + TPythonDump() << SMESH::SMESH_Group_var(_this()) << ".Clear()"; // Clear the group SMESHDS_Group* aGroupDS = dynamic_cast( GetGroupDS() ); @@ -300,7 +297,7 @@ CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs ) myPreMeshInfo->FullLoadFromFile(); // Update Python script - TPythonDump() << "nbAdd = " << _this() << ".Add( " << theIDs << " )"; + TPythonDump() << "nbAdd = " << SMESH::SMESH_Group_var(_this()) << ".Add( " << theIDs << " )"; // Add elements to the group SMESHDS_Group* aGroupDS = dynamic_cast( GetGroupDS() ); @@ -329,7 +326,8 @@ CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs ) myPreMeshInfo->FullLoadFromFile(); // Update Python script - TPythonDump() << "nbDel = " << _this() << ".Remove( " << theIDs << " )"; + TPythonDump() << "nbDel = " << SMESH::SMESH_Group_var(_this()) + << ".Remove( " << theIDs << " )"; // Remove elements from the group SMESHDS_Group* aGroupDS = dynamic_cast( GetGroupDS() ); @@ -382,8 +380,9 @@ AddByPredicate( SMESH::Predicate_ptr thePredicate ) myPreMeshInfo->FullLoadFromFile(); if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){ - TPythonDump()<<_this()<<".AddByPredicate("<FullLoadFromFile(); if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){ - TPythonDump()<<_this()<<".RemoveByPredicate("<FullLoadFromFile(); TPythonDump pd; - long nbAdd = 0; + long prevNb = Size(); SMESHDS_Group* aGroupDS = dynamic_cast( GetGroupDS() ); if (aGroupDS) { - SMESH::long_array_var anIds; - SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow(theSource); - SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow(theSource); - SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow(theSource); - SMESH::Filter_var filter = SMESH::Filter::_narrow(theSource); - if ( !group->_is_nil()) - anIds = group->GetType()==GetType() ? theSource->GetIDs() : new SMESH::long_array(); - else if ( !mesh->_is_nil() ) - anIds = mesh->GetElementsByType( GetType() ); - else if ( !submesh->_is_nil()) - anIds = submesh->GetElementsByType( GetType() ); - else if ( !filter->_is_nil() ) { - filter->SetMesh( GetMeshServant()->_this() ); - anIds = filter->GetElementType()==GetType() ? theSource->GetIDs() : new SMESH::long_array(); - } - else - anIds = theSource->GetIDs(); - for ( int i = 0, total = anIds->length(); i < total; i++ ) { - if ( aGroupDS->Add((int)anIds[i]) ) nbAdd++; - } + SMDS_ElemIteratorPtr elemIt = SMESH_Mesh_i::GetElements( theSource, GetType() ); + while ( elemIt->more() ) + aGroupDS->SMDSGroup().Add( elemIt->next() ); } // Update Python script - pd << "nbAdd = " << _this() << ".AddFrom( " << theSource << " )"; + pd << "nbAdd = " << SMESH::SMESH_Group_var(_this()) << ".AddFrom( " << theSource << " )"; - return nbAdd; + return prevNb - Size(); } //============================================================================= @@ -583,7 +566,7 @@ SMESH::SMESH_Mesh_ptr SMESH_GroupBase_i::GetMesh() { SMESH::SMESH_Mesh_var aMesh; if ( myMeshServant ) - aMesh = SMESH::SMESH_Mesh::_narrow( myMeshServant->_this() ); + aMesh = myMeshServant->_this(); return aMesh._retn(); } @@ -640,7 +623,9 @@ void SMESH_GroupBase_i::SetColor(const SALOMEDS::Color& color) if ( oldColor != aQColor ) { aGroupDS->SetColor(aQColor); - TPythonDump()<<_this()<<".SetColor( SALOMEDS.Color( "<SetColorGroup(color); - TPythonDump()<<_this()<<".SetColorNumber( "<( GetGroupDS() )) grDS->SetPredicate( GetPredicate( myFilter )); - TPythonDump()<< _this() <<".SetFilter( "<