From 885f16afb6fce64fdc545819a5c35ba41ee9babf Mon Sep 17 00:00:00 2001 From: caremoli Date: Mon, 18 Feb 2008 09:44:17 +0000 Subject: [PATCH] CCAR: remove memory leaks --- .../Basic/data_short_port_provides.hxx | 2 ++ .../DSC_User/Datastream/Calcium/Calcium.cxx | 12 ++++++++++ .../Calcium/CalciumProvidesPort.hxx | 2 ++ .../Calcium/calcium_integer_port_uses.hxx | 2 ++ src/DSC/DSC_User/Datastream/GenericPort.hxx | 10 ++++---- .../DSC_User/Datastream/GenericUsesPort.hxx | 11 +++++---- .../Datastream/Palm/PalmCouplingPolicy.hxx | 2 ++ src/DSC/DSC_User/Superv_Component_i.cxx | 23 ++++++++++++++----- src/DSC/DSC_User/Superv_Component_i.hxx | 10 ++++++-- 9 files changed, 58 insertions(+), 16 deletions(-) diff --git a/src/DSC/DSC_User/Basic/data_short_port_provides.hxx b/src/DSC/DSC_User/Basic/data_short_port_provides.hxx index df33f6551..51ae3afd9 100644 --- a/src/DSC/DSC_User/Basic/data_short_port_provides.hxx +++ b/src/DSC/DSC_User/Basic/data_short_port_provides.hxx @@ -26,6 +26,8 @@ #ifndef _DATA_SHORT_PORT_PROVIDES_HXX_ #define _DATA_SHORT_PORT_PROVIDES_HXX_ +#include + #include #include "SALOME_Ports.hh" #include "provides_port.hxx" diff --git a/src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx b/src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx index c17ddb80a..39a8cac49 100644 --- a/src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx +++ b/src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx @@ -43,6 +43,18 @@ extern "C" { dynamic_cast(port)->setDependencyType(depend); } + else if(std::string(type)=="CALCIUM_string") + { + dynamic_cast(port)->setDependencyType(depend); + } + else if(std::string(type)=="CALCIUM_logical") + { + dynamic_cast(port)->setDependencyType(depend); + } + else if(std::string(type)=="CALCIUM_complex") + { + dynamic_cast(port)->setDependencyType(depend); + } else { std::cerr << "unknown type:" << std::endl; diff --git a/src/DSC/DSC_User/Datastream/Calcium/CalciumProvidesPort.hxx b/src/DSC/DSC_User/Datastream/Calcium/CalciumProvidesPort.hxx index 075132663..e22288f6a 100644 --- a/src/DSC/DSC_User/Datastream/Calcium/CalciumProvidesPort.hxx +++ b/src/DSC/DSC_User/Datastream/Calcium/CalciumProvidesPort.hxx @@ -6,6 +6,8 @@ #ifndef _CALCIUM_PORT_PROVIDES_HXX_ #define _CALCIUM_PORT_PROVIDES_HXX_ +#include + #include "Calcium_Ports.hh" #include "CalciumGenericProvidesPort.hxx" #include "CalciumCouplingPolicy.hxx" diff --git a/src/DSC/DSC_User/Datastream/Calcium/calcium_integer_port_uses.hxx b/src/DSC/DSC_User/Datastream/Calcium/calcium_integer_port_uses.hxx index 6733cdbdf..3216a20f4 100644 --- a/src/DSC/DSC_User/Datastream/Calcium/calcium_integer_port_uses.hxx +++ b/src/DSC/DSC_User/Datastream/Calcium/calcium_integer_port_uses.hxx @@ -29,6 +29,8 @@ #ifndef _CALCIUM_INTEGER_PORT_USES_HXX_ #define _CALCIUM_INTEGER_PORT_USES_HXX_ +#include + #include "Calcium_Ports.hh" #include "CalciumGenericUsesPort.hxx" diff --git a/src/DSC/DSC_User/Datastream/GenericPort.hxx b/src/DSC/DSC_User/Datastream/GenericPort.hxx index fbb324341..dd6005780 100644 --- a/src/DSC/DSC_User/Datastream/GenericPort.hxx +++ b/src/DSC/DSC_User/Datastream/GenericPort.hxx @@ -103,10 +103,12 @@ GenericPort::GenericPort() : template < typename DataManipulator, typename COUPLING_POLICY> GenericPort::~GenericPort() { typename DataTable::iterator it; - // for (it=storedDatas.begin(); it!=storedDatas.end(); ++it) { - // std::cout << "~GenericPort() : destruction de la donnnée associée au DataId :"<< (*it).first << std::endl; - // DataManipulator::delete_data( (*it).second ); - // } + for (it=storedDatas.begin(); it!=storedDatas.end(); ++it) { +#ifdef _DEBUG_ + std::cerr << "~GenericPort() : destruction de la donnnée associée au DataId :"<< (*it).first << std::endl; +#endif + DataManipulator::delete_data( (*it).second ); + } } template < typename DataManipulator, typename COUPLING_POLICY> void diff --git a/src/DSC/DSC_User/Datastream/GenericUsesPort.hxx b/src/DSC/DSC_User/Datastream/GenericUsesPort.hxx index 2c01e49af..effed2b07 100644 --- a/src/DSC/DSC_User/Datastream/GenericUsesPort.hxx +++ b/src/DSC/DSC_User/Datastream/GenericUsesPort.hxx @@ -72,7 +72,10 @@ GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::Gen } template -GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::~GenericUsesPort() {} +GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::~GenericUsesPort() +{ + delete _my_ports; +} template const char * @@ -87,7 +90,7 @@ void GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::put( CorbaInDataType data, TimeType time, TagType tag) { - typedef typename CorbaPortType::_ptr_type CorbaPortTypePtr; + typedef typename CorbaPortType::_var_type CorbaPortTypeVar; if (!_my_ports) throw DSC_Exception(LOC("There is no connected provides port to communicate with.")); @@ -101,7 +104,7 @@ GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::put // OLD : DataType copyOfData; // = data; PB1 for(int i = 0; i < _my_ports->length(); i++) { - CorbaPortTypePtr port = CorbaPortType::_narrow((*_my_ports)[i]); + CorbaPortTypeVar port = CorbaPortType::_narrow((*_my_ports)[i]); //if (i) { PB1 //OLD : copyOfData = DataManipulator::clone(data); #ifdef _DEBUG_ @@ -137,7 +140,7 @@ GenericUsesPort< DataManipulator, CorbaPortType, repositoryName, UsesPort #ifdef _DEBUG_ std::cerr << "GenericUsesPort::uses_port_changed" << std::endl; #endif - _my_ports = new Engines::DSC::uses_port(*new_uses_port); + _my_ports = new_uses_port; } #endif diff --git a/src/DSC/DSC_User/Datastream/Palm/PalmCouplingPolicy.hxx b/src/DSC/DSC_User/Datastream/Palm/PalmCouplingPolicy.hxx index 30cdf27d7..c5f57fff4 100644 --- a/src/DSC/DSC_User/Datastream/Palm/PalmCouplingPolicy.hxx +++ b/src/DSC/DSC_User/Datastream/Palm/PalmCouplingPolicy.hxx @@ -29,6 +29,8 @@ #ifndef _PALM_COUPLING_POLICIES_HXX_ #define _PALM_COUPLING_POLICIES_HXX_ +#include + #include #include #include "DataIdFilter.hxx" diff --git a/src/DSC/DSC_User/Superv_Component_i.cxx b/src/DSC/DSC_User/Superv_Component_i.cxx index 72cbef19b..3f2a3e972 100644 --- a/src/DSC/DSC_User/Superv_Component_i.cxx +++ b/src/DSC/DSC_User/Superv_Component_i.cxx @@ -60,6 +60,11 @@ Superv_Component_i::~Superv_Component_i() { delete begin->second; } + + my_superv_ports_it = my_superv_ports.begin(); + for(;my_superv_ports_it != my_superv_ports.end();my_superv_ports_it++) + delete my_superv_ports_it->second; + } void @@ -179,9 +184,11 @@ Superv_Component_i::add_port(provides_port * port, try { - Engines_DSC_interface::add_provides_port(port->get_port_ref(), + Ports::PortProperties_var portproperties=port->get_port_properties(); + Ports::Port_var portref=port->get_port_ref(); + Engines_DSC_interface::add_provides_port(portref, provides_port_name, - port->get_port_properties()); + portproperties); superv_port_t * new_superv_port = new superv_port_t(); new_superv_port->p_ref = port; @@ -209,9 +216,10 @@ Superv_Component_i::add_port(uses_port * port, assert(uses_port_name); try { + Ports::PortProperties_var portproperties=port->get_port_properties(); Engines_DSC_interface::add_uses_port(port->get_repository_id(), uses_port_name, - port->get_port_properties()); + portproperties); superv_port_t * new_superv_port = new superv_port_t(); new_superv_port->u_ref = port; my_superv_ports[uses_port_name] = new_superv_port; @@ -236,7 +244,7 @@ Superv_Component_i::get_port(provides_port *& port, assert(provides_port_name); try { - Engines_DSC_interface::get_provides_port(provides_port_name, false); + Ports::Port_var portref=Engines_DSC_interface::get_provides_port(provides_port_name, false); port = my_superv_ports[provides_port_name]->p_ref; } catch (const Engines::DSC::PortNotDefined&) { throw PortNotDefined( LOC(OSS()<< "Le port provides " @@ -255,7 +263,8 @@ Superv_Component_i::get_port(uses_port *& port, assert(uses_port_name); try { - Engines_DSC_i::get_uses_port(uses_port_name); + Engines::DSC::uses_port * portseq=Engines_DSC_i::get_uses_port(uses_port_name); + delete portseq; port = my_superv_ports[uses_port_name]->u_ref; } catch (const Engines::DSC::PortNotDefined&) { throw PortNotDefined( LOC(OSS()<< "Le port uses " @@ -286,8 +295,10 @@ Superv_Component_i::uses_port_changed(const char* uses_port_name, { my_superv_ports_it = my_superv_ports.find(uses_port_name); if (my_superv_ports_it != my_superv_ports.end()) - my_superv_ports[uses_port_name]->u_ref->uses_port_changed(new_uses_port, + my_superv_ports[uses_port_name]->u_ref->uses_port_changed(new Engines::DSC::uses_port(*new_uses_port), message); + //delete the copy made by the caller + delete new_uses_port; } diff --git a/src/DSC/DSC_User/Superv_Component_i.hxx b/src/DSC/DSC_User/Superv_Component_i.hxx index cf61ce458..174380f05 100644 --- a/src/DSC/DSC_User/Superv_Component_i.hxx +++ b/src/DSC/DSC_User/Superv_Component_i.hxx @@ -263,6 +263,11 @@ private: // A Superv_Component port. struct superv_port_t { superv_port_t():u_ref(NULL),p_ref(NULL){}; + ~superv_port_t() + { + if(u_ref)delete u_ref; + if(p_ref)delete p_ref; + }; // For uses ports. uses_port * u_ref; // For provides ports. @@ -346,11 +351,12 @@ Superv_Component_i::get_port( const char * port_name) try { if ( superv_port->p_ref != NULL ) { port = superv_port->p_ref; - Engines_DSC_interface::get_provides_port(port_name, false); + Ports::Port_var portref=Engines_DSC_interface::get_provides_port(port_name, false); } else if ( superv_port->u_ref != NULL ) { port = superv_port->u_ref; - Engines_DSC_i::get_uses_port(port_name); + Engines::DSC::uses_port * portseq=Engines_DSC_i::get_uses_port(port_name); + delete portseq; } else { throw UnexpectedState( LOC(OSS()<< "Internal Error superv_port struct is inconsistent ")); -- 2.39.2