From 7d620cf97afbb98fd55fc0cbd03ba39e6796f5e1 Mon Sep 17 00:00:00 2001 From: eap Date: Fri, 14 Dec 2012 14:02:36 +0000 Subject: [PATCH] 21948: EDF SMESH : Memory is not freed when deleting a mesh Elimenate memory leaks on CORBA objects, servants of SALOMEDS objects etc --- src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx | 9 ++-- src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx | 9 ++-- .../BLSURFPlugin_Hypothesis_i.cxx | 53 ++++++++++--------- src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx | 10 ++-- 4 files changed, 38 insertions(+), 43 deletions(-) diff --git a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx index 01cc508..528a51e 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx @@ -443,13 +443,10 @@ TopoDS_Shape BLSURFPlugin_BLSURF::entryToShape(std::string entry) GEOM::GEOM_Object_var aGeomObj; TopoDS_Shape S = TopoDS_Shape(); SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() ); - SALOMEDS::GenericAttribute_var anAttr; - - if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) { - SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - CORBA::String_var aVal = anIOR->Value(); - CORBA::Object_var obj = myStudy->ConvertIORToObject(aVal); + if (!aSObj->_is_nil()) { + CORBA::Object_var obj = aSObj->GetObject(); aGeomObj = GEOM::GEOM_Object::_narrow(obj); + aSObj->UnRegister(); } if ( !aGeomObj->_is_nil() ) S = smeshGen_i->GeomObjectToShape( aGeomObj.in() ); diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx index ada8a38..ab6e14d 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx @@ -197,13 +197,10 @@ TopoDS_Shape BLSURFPlugin_Hypothesis::entryToShape(std::string entry) TopoDS_Shape S = TopoDS_Shape(); SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() ); - SALOMEDS::GenericAttribute_var anAttr; - - if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) { - SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - CORBA::String_var aVal = anIOR->Value(); - CORBA::Object_var obj = myStudy->ConvertIORToObject(aVal); + if (!aSObj->_is_nil() ) { + CORBA::Object_var obj = aSObj->GetObject(); aGeomObj = GEOM::GEOM_Object::_narrow(obj); + aSObj->UnRegister(); } if ( !aGeomObj->_is_nil() ) S = smeshGen_i->GeomObjectToShape( aGeomObj.in() ); diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx index 77af19a..ca776fa 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx @@ -24,17 +24,20 @@ // --- // #include "BLSURFPlugin_Hypothesis_i.hxx" -#include "SMESH_Gen.hxx" -#include "SMESH_Gen_i.hxx" -#include "SMESH_PythonDump.hxx" -#include "GEOM_Object.hxx" -#include "Utils_CorbaException.hxx" -#include "utilities.h" +#include +#include +#include + +#include + +#include +#include +#include #include #include -#include "boost/regex.hpp" +#include //============================================================================= /*! @@ -1242,7 +1245,7 @@ void BLSURFPlugin_Hypothesis_i::SetAttractorGeom(GEOM::GEOM_Object_ptr theFace, if (theFaceEntry.empty()) { aName = "Face_"; aName += theFace->GetEntry(); - SALOMEDS::SObject_ptr theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); + SALOMEDS::SObject_wrap theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); if (!theSFace->_is_nil()) theFaceEntry = theSFace->GetID(); } @@ -1259,7 +1262,7 @@ void BLSURFPlugin_Hypothesis_i::SetAttractorGeom(GEOM::GEOM_Object_ptr theFace, if (theAttractor->GetShapeType() == GEOM::COMPOUND) aName = "Compound_"; aName += theAttractor->GetEntry(); - SALOMEDS::SObject_ptr theSAtt = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theAttractor, aName.c_str()); + SALOMEDS::SObject_wrap theSAtt = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theAttractor, aName.c_str()); if (!theSAtt->_is_nil()) theAttEntry = theSAtt->GetID(); } @@ -1286,7 +1289,7 @@ void BLSURFPlugin_Hypothesis_i::UnsetAttractorGeom(GEOM::GEOM_Object_ptr theFace if (theFaceEntry.empty()) { aName = "Face_"; aName += theFace->GetEntry(); - SALOMEDS::SObject_ptr theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); + SALOMEDS::SObject_wrap theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); if (!theSFace->_is_nil()) theFaceEntry = theSFace->GetID(); } @@ -1706,7 +1709,7 @@ bool BLSURFPlugin_Hypothesis_i::SetEnforcedVertex(GEOM::GEOM_Object_ptr theFace, if (theFace->GetShapeType() == GEOM::COMPOUND) aName = "Compound_"; aName += theFace->GetEntry(); - SALOMEDS::SObject_ptr theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); + SALOMEDS::SObject_wrap theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); if (!theSFace->_is_nil()) theFaceEntry = theSFace->GetID(); } @@ -1744,7 +1747,7 @@ bool BLSURFPlugin_Hypothesis_i::SetEnforcedVertexNamed(GEOM::GEOM_Object_ptr the if (theFace->GetShapeType() == GEOM::COMPOUND) aName = "Compound_"; aName += theFace->GetEntry(); - SALOMEDS::SObject_ptr theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); + SALOMEDS::SObject_wrap theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); if (!theSFace->_is_nil()) theFaceEntry = theSFace->GetID(); } @@ -1799,7 +1802,7 @@ bool BLSURFPlugin_Hypothesis_i::SetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theF if (theFace->GetShapeType() == GEOM::COMPOUND) aName = "Compound_"; aName += theFace->GetEntry(); - SALOMEDS::SObject_ptr theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); + SALOMEDS::SObject_wrap theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); if (!theSFace->_is_nil()) theFaceEntry = theSFace->GetID(); } @@ -1812,7 +1815,7 @@ bool BLSURFPlugin_Hypothesis_i::SetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theF if (theVertex->GetShapeType() == GEOM::COMPOUND) aName = "Compound_"; aName += theVertex->GetEntry(); - SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theVertex, aName.c_str()); + SALOMEDS::SObject_wrap theSVertex = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theVertex, aName.c_str()); if (!theSVertex->_is_nil()) theVertexEntry = theSVertex->GetID(); } @@ -1854,7 +1857,7 @@ bool BLSURFPlugin_Hypothesis_i::SetEnforcedVertexWithGroup(GEOM::GEOM_Object_ptr if (theFace->GetShapeType() == GEOM::COMPOUND) aName = "Compound_"; aName += theFace->GetEntry(); - SALOMEDS::SObject_ptr theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); + SALOMEDS::SObject_wrap theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); if (!theSFace->_is_nil()) theFaceEntry = theSFace->GetID(); } @@ -1894,7 +1897,7 @@ bool BLSURFPlugin_Hypothesis_i::SetEnforcedVertexNamedWithGroup(GEOM::GEOM_Objec if (theFace->GetShapeType() == GEOM::COMPOUND) aName = "Compound_"; aName += theFace->GetEntry(); - SALOMEDS::SObject_ptr theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); + SALOMEDS::SObject_wrap theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); if (!theSFace->_is_nil()) theFaceEntry = theSFace->GetID(); } @@ -1940,7 +1943,7 @@ bool BLSURFPlugin_Hypothesis_i::SetEnforcedVertexGeomWithGroup(GEOM::GEOM_Object if (theFace->GetShapeType() == GEOM::COMPOUND) aName = "Compound_"; aName += theFace->GetEntry(); - SALOMEDS::SObject_ptr theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); + SALOMEDS::SObject_wrap theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); if (!theSFace->_is_nil()) theFaceEntry = theSFace->GetID(); } @@ -1953,7 +1956,7 @@ bool BLSURFPlugin_Hypothesis_i::SetEnforcedVertexGeomWithGroup(GEOM::GEOM_Object if (theVertex->GetShapeType() == GEOM::COMPOUND) aName = "Compound_"; aName += theVertex->GetEntry(); - SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theVertex, aName.c_str()); + SALOMEDS::SObject_wrap theSVertex = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theVertex, aName.c_str()); if (!theSVertex->_is_nil()) theVertexEntry = theSVertex->GetID(); } @@ -1995,7 +1998,7 @@ bool BLSURFPlugin_Hypothesis_i::SetEnforcedVertexGeomWithGroup(GEOM::GEOM_Object // if (theFace->GetShapeType() == GEOM::COMPOUND) // aName = "Compound_"; // aName += theFace->GetEntry(); -// SALOMEDS::SObject_ptr theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); +// SALOMEDS::SObject_wrap theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); // if (!theSFace->_is_nil()) // theFaceEntry = theSFace->GetID(); // } @@ -2034,7 +2037,7 @@ BLSURFPlugin::TEnfVertexList* BLSURFPlugin_Hypothesis_i::GetEnforcedVertices(GEO if (theFace->GetShapeType() == GEOM::COMPOUND) aName = "Compound_"; aName += theFace->GetEntry(); - SALOMEDS::SObject_ptr theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); + SALOMEDS::SObject_wrap theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); if (!theSFace->_is_nil()) theFaceEntry = theSFace->GetID(); } @@ -2070,7 +2073,7 @@ bool BLSURFPlugin_Hypothesis_i::UnsetEnforcedVertex(GEOM::GEOM_Object_ptr theFac if (theFace->GetShapeType() == GEOM::COMPOUND) aName = "Compound_"; aName += theFace->GetEntry(); - SALOMEDS::SObject_ptr theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); + SALOMEDS::SObject_wrap theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); if (!theSFace->_is_nil()) theFaceEntry = theSFace->GetID(); } @@ -2121,7 +2124,7 @@ bool BLSURFPlugin_Hypothesis_i::UnsetEnforcedVertexGeom(GEOM::GEOM_Object_ptr th if (theFace->GetShapeType() == GEOM::COMPOUND) aName = "Compound_"; aName += theFace->GetEntry(); - SALOMEDS::SObject_ptr theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); + SALOMEDS::SObject_wrap theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); if (!theSFace->_is_nil()) theFaceEntry = theSFace->GetID(); } @@ -2134,7 +2137,7 @@ bool BLSURFPlugin_Hypothesis_i::UnsetEnforcedVertexGeom(GEOM::GEOM_Object_ptr th if (theVertex->GetShapeType() == GEOM::COMPOUND) aName = "Compound_"; aName += theVertex->GetEntry(); - SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theVertex, aName.c_str()); + SALOMEDS::SObject_wrap theSVertex = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theVertex, aName.c_str()); if (!theSVertex->_is_nil()) theVertexEntry = theSVertex->GetID(); } @@ -2169,7 +2172,7 @@ bool BLSURFPlugin_Hypothesis_i::UnsetEnforcedVertices(GEOM::GEOM_Object_ptr theF if (theFace->GetShapeType() == GEOM::COMPOUND) aName = "Compound_"; aName += theFace->GetEntry(); - SALOMEDS::SObject_ptr theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); + SALOMEDS::SObject_wrap theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); if (!theSFace->_is_nil()) theFaceEntry = theSFace->GetID(); } @@ -2492,7 +2495,7 @@ void BLSURFPlugin_Hypothesis_i::SetInternalEnforcedVertexWithGroup(GEOM::GEOM_Ob if (theFace->GetShapeType() == GEOM::COMPOUND) aName = "Compound_"; aName += theFace->GetEntry(); - SALOMEDS::SObject_ptr theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); + SALOMEDS::SObject_wrap theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str()); if (!theSFace->_is_nil()) theFaceEntry = theSFace->GetID(); } diff --git a/src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx b/src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx index daee40e..8ab1ca5 100644 --- a/src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx +++ b/src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx @@ -2683,14 +2683,12 @@ LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr() CORBA::Object_var BLSURFPluginGUI_HypothesisCreator::entryToObject(QString entry) { SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen(); - SALOMEDS::Study_ptr myStudy = smeshGen_i->GetCurrentStudy(); + SALOMEDS::Study_var myStudy = smeshGen_i->GetCurrentStudy(); CORBA::Object_var obj; - SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.toStdString().c_str() ); - if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) { - SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - CORBA::String_var aVal = anIOR->Value(); - obj = myStudy->ConvertIORToObject(aVal); + if (!aSObj->_is_nil()) { + obj = aSObj->GetObject(); + aSObj->UnRegister(); } return obj; } -- 2.39.2