]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
CCAR: remove more memory leaks in SALOMEDS
authorcaremoli <caremoli>
Wed, 16 Sep 2009 13:18:51 +0000 (13:18 +0000)
committercaremoli <caremoli>
Wed, 16 Sep 2009 13:18:51 +0000 (13:18 +0000)
src/SALOMEDS/SALOMEDS_StudyManager_i.cxx
src/SALOMEDS/SALOMEDS_Study_i.cxx
src/SALOMEDS/SALOMEDS_Study_i.hxx
src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx
src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx
src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx

index f2759d888e6812c961703694a50d241f583d38c8..0f2f93ac68ae6d11299e9c3d3cf95f046d5d565a 100644 (file)
@@ -122,7 +122,8 @@ SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::NewStudy(const char* study_name)
 
   MESSAGE("NewStudy : Creating the CORBA servant holding it... ");
 
-  SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(aStudyImpl, _orb);
+  SALOMEDS_Study_i *Study_servant = SALOMEDS_Study_i::GetStudyServant(aStudyImpl, _orb);
+  PortableServer::ObjectId_var servantid = _poa->activate_object(Study_servant); // to use poa registered in _mapOfPOA
   SALOMEDS::Study_var Study = Study_servant->_this();
 
   // Register study in the naming service
@@ -163,8 +164,9 @@ SALOMEDS::Study_ptr  SALOMEDS_StudyManager_i::Open(const char* aUrl)
   MESSAGE("Open : Creating the CORBA servant holding it... ");
 
   // Temporary aStudyUrl in place of study name
-  SALOMEDS_Study_i * Study_servant = new SALOMEDS_Study_i(aStudyImpl, _orb);
-  SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(Study_servant->_this());
+  SALOMEDS_Study_i * Study_servant = SALOMEDS_Study_i::GetStudyServant(aStudyImpl, _orb);
+  PortableServer::ObjectId_var servantid = _poa->activate_object(Study_servant); // to use poa register in _mapOfPOA
+  SALOMEDS::Study_var Study = Study_servant->_this();
 
   // Assign the value of the IOR in the study->root
   CORBA::String_var IORStudy = _orb->object_to_string(Study);
@@ -175,7 +177,7 @@ SALOMEDS::Study_ptr  SALOMEDS_StudyManager_i::Open(const char* aUrl)
   if(!_name_service->Change_Directory("/Study")) MESSAGE( "Unable to access the study directory" )
   else _name_service->Register(Study, CORBA::string_dup(aStudyImpl->Name().c_str()));
 
-  return Study;
+  return Study._retn();
 }
 
 
@@ -202,6 +204,14 @@ void SALOMEDS_StudyManager_i::Close(SALOMEDS::Study_ptr aStudy)
   SALOMEDS::unlock();
   aStudy->Close();
   SALOMEDS::lock();
+
+  //remove study servant
+  PortableServer::POA_ptr poa=GetPOA(aStudy);
+  PortableServer::ServantBase* aservant=poa->reference_to_servant(aStudy);
+  PortableServer::ObjectId_var anObjectId = poa->servant_to_id(aservant);
+  poa->deactivate_object(anObjectId.in());
+  aservant->_remove_ref(); // decrement for the call to reference_to_servant
+  aservant->_remove_ref(); // to delete the object
 }
 
 //============================================================================
@@ -313,10 +323,8 @@ SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::GetStudyByName(const char* aStudyNa
     return SALOMEDS::Study::_nil();
   }
 
-  SALOMEDS_Study_i* aStudy_servant = new SALOMEDS_Study_i(aStudyImpl, _orb);
-  SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(aStudy_servant->_this());
-
-  return aStudy._retn();
+  SALOMEDS_Study_i* aStudy_servant = SALOMEDS_Study_i::GetStudyServant(aStudyImpl, _orb);
+  return aStudy_servant->_this();
 }
 
 //============================================================================
@@ -336,11 +344,8 @@ SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::GetStudyByID(CORBA::Short aStudyID)
     return SALOMEDS::Study::_nil();
   }
 
-  SALOMEDS_Study_i* aStudy_servant = new SALOMEDS_Study_i(aStudyImpl, _orb);
-  CORBA::Object_var obj = aStudy_servant->_this();
-  SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(obj);
-
-  return aStudy._retn();
+  SALOMEDS_Study_i* aStudy_servant = SALOMEDS_Study_i::GetStudyServant(aStudyImpl, _orb);
+  return aStudy_servant->_this();
 }
 
 
@@ -355,7 +360,8 @@ CORBA::Boolean SALOMEDS_StudyManager_i::CanCopy(SALOMEDS::SObject_ptr theObject)
 
   SALOMEDS::Study_var aStudy = theObject->GetStudy();
   SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
-  SALOMEDSImpl_SObject anObject = aStudyImpl->GetSObject(theObject->GetID());
+  CORBA::String_var anID = theObject->GetID();
+  SALOMEDSImpl_SObject anObject = aStudyImpl->GetSObject(anID.in());
 
   SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
   bool ret = _impl->CanCopy(anObject, aDriver);
@@ -374,7 +380,8 @@ CORBA::Boolean SALOMEDS_StudyManager_i::Copy(SALOMEDS::SObject_ptr theObject)
 
   SALOMEDS::Study_var aStudy = theObject->GetStudy();
   SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
-  SALOMEDSImpl_SObject anObject = aStudyImpl->GetSObject(theObject->GetID());
+  CORBA::String_var anID = theObject->GetID();
+  SALOMEDSImpl_SObject anObject = aStudyImpl->GetSObject(anID.in());
 
   SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
   bool ret = _impl->Copy(anObject, aDriver);
@@ -393,7 +400,8 @@ CORBA::Boolean SALOMEDS_StudyManager_i::CanPaste(SALOMEDS::SObject_ptr theObject
 
   SALOMEDS::Study_var aStudy = theObject->GetStudy();
   SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
-  SALOMEDSImpl_SObject anObject = aStudyImpl->GetSObject(theObject->GetID());
+  CORBA::String_var anID = theObject->GetID();
+  SALOMEDSImpl_SObject anObject = aStudyImpl->GetSObject(anID.in());
 
   SALOMEDS_Driver_i* aDriver = GetDriver(anObject, _orb);
   bool ret = _impl->CanPaste(anObject, aDriver);
@@ -415,7 +423,8 @@ SALOMEDS::SObject_ptr SALOMEDS_StudyManager_i::Paste(SALOMEDS::SObject_ptr theOb
   SALOMEDS::Study_var aStudy = theObject->GetStudy();
 
   SALOMEDSImpl_Study* aStudyImpl = _impl->GetStudyByID(aStudy->StudyId());
-  SALOMEDSImpl_SObject anObject = aStudyImpl->GetSObject(theObject->GetID());
+  CORBA::String_var anID = theObject->GetID();
+  SALOMEDSImpl_SObject anObject = aStudyImpl->GetSObject(anID.in());
   SALOMEDSImpl_SObject aNewSO;
 
   try {
index fb0e28abdf407df09442b4e09ede8351b8ca64f5..c6127cc21231a2a80d6d51b3b89ddc828e441f15 100644 (file)
@@ -25,6 +25,7 @@
 //
 #include "utilities.h"
 #include "SALOMEDS_Study_i.hxx"
+#include "SALOMEDS_StudyManager_i.hxx"
 #include "SALOMEDS_UseCaseIterator_i.hxx"
 #include "SALOMEDS_GenericAttribute_i.hxx"
 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
@@ -55,6 +56,8 @@
 
 using namespace std;
 
+std::map<SALOMEDSImpl_Study* , SALOMEDS_Study_i*> SALOMEDS_Study_i::_mapOfStudies;
+
 //============================================================================
 /*! Function : SALOMEDS_Study_i
  *  Purpose  : SALOMEDS_Study_i constructor
@@ -76,6 +79,13 @@ SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl,
 //============================================================================
 SALOMEDS_Study_i::~SALOMEDS_Study_i()
 {
+  //delete the builder servant
+  PortableServer::POA_var poa=_builder->_default_POA();
+  PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder);
+  poa->deactivate_object(anObjectId.in());
+  _builder->_remove_ref();
+  //delete implementation
+  delete _impl;
 }  
 
 //============================================================================
@@ -421,7 +431,8 @@ SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject
 {
   SALOMEDS::Locker lock; 
 
-  SALOMEDSImpl_SObject aSO = _impl->GetSObject(theSO->GetID());
+  CORBA::String_var anID=theSO->GetID();
+  SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in());
   SALOMEDSImpl_ChildIterator anItr(aSO);
 
   //Create iterator
@@ -581,6 +592,18 @@ SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::
   return SALOMEDS::Study::_nil();
 }
 
+SALOMEDS_Study_i* SALOMEDS_Study_i::GetStudyServant(SALOMEDSImpl_Study* aStudyImpl, CORBA::ORB_ptr orb)
+{
+  if (_mapOfStudies.find(aStudyImpl) != _mapOfStudies.end()) 
+    return _mapOfStudies[aStudyImpl];
+  else
+    {
+      SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(aStudyImpl, orb);
+      _mapOfStudies[aStudyImpl]=Study_servant;
+      return Study_servant;
+    }
+}
+
 void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute) 
 {
   SALOMEDS::Locker lock; 
@@ -685,8 +708,13 @@ void SALOMEDS_Study_i::Close()
       catch (CORBA::Exception&) 
         {/*pass*/ }
     }
+    sco->Destroy();
   }
 
+  //Does not need any more this iterator
+  itcomponent->Destroy();
+
+
   _impl->Close();
 }
 
index 52ada453c2b36b400a83fdb510c08abcde100572..d53e660d60b3da3afca925b8e1d5453f5339e64b 100644 (file)
@@ -51,6 +51,7 @@ private:
   CORBA::ORB_var                 _orb;
   SALOMEDSImpl_Study*            _impl;  
   SALOMEDS_StudyBuilder_i*       _builder;    
+  static std::map<SALOMEDSImpl_Study*, SALOMEDS_Study_i*> _mapOfStudies;
 
 public:
 
@@ -244,6 +245,7 @@ public:
   virtual void  StudyId(CORBA::Short id);
 
   static SALOMEDS::Study_ptr GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb);
+  static SALOMEDS_Study_i* GetStudyServant(SALOMEDSImpl_Study*, CORBA::ORB_ptr orb);
 
   static void IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute);
 
index c70ac8ed539d43ea3869b2cbad4f0ede5b1d9cc1..588c83d32e7143a83e33cb1368783783da10ee2b 100644 (file)
@@ -56,7 +56,6 @@ SALOMEDSImpl_AttributeIOR* SALOMEDSImpl_AttributeIOR::Set (const DF_Label& L,
   }
 
   A->SetValue(S); 
-  SALOMEDSImpl_Study::IORUpdated(A);
   return A;
 }
 
@@ -73,6 +72,7 @@ void SALOMEDSImpl_AttributeIOR::SetValue(const std::string& theValue)
   Backup();
   myString = theValue;
 
+  //add IOR entry in study
   SALOMEDSImpl_Study::IORUpdated(this);
 }
 
index 7d40c15dbb10c51dfd3391b5fdaec2e6bbb858b7..edc77e49fc89697bd157cad653079bc9bf4c7478 100644 (file)
@@ -965,6 +965,15 @@ void SALOMEDSImpl_Study::UpdateIORLabelMap(const string& anIOR,const string& anE
   myIORLabels[anIOR] = aLabel;
 }
 
+void SALOMEDSImpl_Study::DeleteIORLabelMapItem(const std::string& anIOR)
+{
+  if (myIORLabels.find(anIOR) != myIORLabels.end()) 
+    {
+      //remove the ior entry
+      myIORLabels.erase(anIOR);
+    }
+}
+
 SALOMEDSImpl_Study* SALOMEDSImpl_Study::GetStudy(const DF_Label& theLabel)
 {
   SALOMEDSImpl_StudyHandle* Att;
index 8e29584c30c71ef9d095e3922eb5eb576d1fc01b..55a2bca77854ff4745f3b75ed8eafd5f05b13e1f 100644 (file)
@@ -196,6 +196,7 @@ public:
 
   virtual void  StudyId(int id);
   
+  virtual void DeleteIORLabelMapItem(const std::string& anIOR);
   virtual void UpdateIORLabelMap(const std::string& anIOR, const std::string& aLabel);
   
   virtual std::vector<SALOMEDSImpl_SObject> FindDependances(const SALOMEDSImpl_SObject& anObject);
index 7edbea0230ed7582e92736a42292c2c093cf82ac..4ec0d3b39959b05c5fb8748e23fbfbfb63bf19ab 100644 (file)
@@ -205,6 +205,7 @@ bool SALOMEDSImpl_StudyBuilder::RemoveObject(const SALOMEDSImpl_SObject& anObjec
 
   SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map
   if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
+    _study->DeleteIORLabelMapItem(anAttr->Value());
   }
 
   Lab.ForgetAllAttributes();
@@ -240,6 +241,7 @@ bool SALOMEDSImpl_StudyBuilder::RemoveObjectWithChildren(const SALOMEDSImpl_SObj
   }
   SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map
   if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
+    _study->DeleteIORLabelMapItem(anAttr->Value());
   }
 
   DF_ChildIterator it(Lab, true);
@@ -252,6 +254,7 @@ bool SALOMEDSImpl_StudyBuilder::RemoveObjectWithChildren(const SALOMEDSImpl_SObj
     }
     SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map
     if ((anAttr=(SALOMEDSImpl_AttributeIOR*)aLabel.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
+      _study->DeleteIORLabelMapItem(anAttr->Value());
     }
   }
 
@@ -533,6 +536,7 @@ bool SALOMEDSImpl_StudyBuilder::RemoveAttribute(const SALOMEDSImpl_SObject& anOb
   if (aTypeOfAttribute == string("AttributeIOR")) { // Remove from IORLabel map
     SALOMEDSImpl_AttributeIOR* anAttr = NULL;
     if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
+      _study->DeleteIORLabelMapItem(anAttr->Value());
     }
   }