Skip to content
Snippets Groups Projects
Commit b5a46ad5 authored by Jade PHAM's avatar Jade PHAM
Browse files

memory leak correction

parent bca1fb15
No related branches found
No related tags found
1 merge request!2memory leak correction
...@@ -55,17 +55,17 @@ void TangoEthernetLink::check_proxy (void) throw (Tango::DevFailed) ...@@ -55,17 +55,17 @@ void TangoEthernetLink::check_proxy (void) throw (Tango::DevFailed)
try try
{ {
//- try if (_ethernet_proxy==0)
this->_ethernet_proxy = new Tango::DeviceProxy(_communication_Device_name.c_str()); this->_ethernet_proxy = new Tango::DeviceProxy(_communication_Device_name.c_str());
_ethernet_proxy->ping(); _ethernet_proxy->ping();
_is_ethernet_proxy_ok = true; _is_ethernet_proxy_ok = true;
} }
catch(Tango::DevFailed& df ) catch(Tango::DevFailed& df )
{ {
if( this->_ethernet_proxy ) if(_ethernet_proxy )
{ {
delete this->_ethernet_proxy; delete _ethernet_proxy;
this->_ethernet_proxy = 0; _ethernet_proxy = 0;
} }
_is_ethernet_proxy_ok = false; _is_ethernet_proxy_ok = false;
description = "Unable to create proxy on : " + _communication_Device_name; description = "Unable to create proxy on : " + _communication_Device_name;
...@@ -77,10 +77,10 @@ void TangoEthernetLink::check_proxy (void) throw (Tango::DevFailed) ...@@ -77,10 +77,10 @@ void TangoEthernetLink::check_proxy (void) throw (Tango::DevFailed)
} }
catch(...) catch(...)
{ {
if( this->_ethernet_proxy ) if( _ethernet_proxy )
{ {
delete this->_ethernet_proxy; delete _ethernet_proxy;
this->_ethernet_proxy = 0; _ethernet_proxy = 0;
} }
_is_ethernet_proxy_ok = false; _is_ethernet_proxy_ok = false;
description = "Unable to create proxy on : " + _communication_Device_name + "\nmemory allocation failed."; description = "Unable to create proxy on : " + _communication_Device_name + "\nmemory allocation failed.";
...@@ -105,33 +105,8 @@ void TangoEthernetLink::write (std::string command_to_send) throw (Tango::DevFa ...@@ -105,33 +105,8 @@ void TangoEthernetLink::write (std::string command_to_send) throw (Tango::DevFa
Tango::DeviceData dd_in; Tango::DeviceData dd_in;
Tango::DevString argin = 0; Tango::DevString argin = 0;
try
{
argin = new char [command_to_send.size() + 1]; argin = new char [command_to_send.size() + 1];
strcpy(argin, command_to_send.c_str()); strcpy(argin, command_to_send.c_str());
}
catch(Tango::DevFailed& df )
{
if( argin )
{
delete [] argin;
argin = 0;
}
description = "Unable to write command : " + command_to_send + + "\nmemory allocation failed.";
Tango::Except::re_throw_exception (df,
(const char*)"ALLOCATION_ERROR",
description.c_str(),
(const char*)"TangoEthernetLink::write");
}
catch(...)
{
description = "Unable to write command : " + command_to_send + "\nmemory allocation failed.";
Tango::Except::throw_exception (
(const char*)"ALLOCATION_ERROR",
description.c_str(),
(const char*)"TangoEthernetLink::write");
}
try try
{ {
//- try //- try
...@@ -171,6 +146,10 @@ void TangoEthernetLink::write (std::string command_to_send) throw (Tango::DevFa ...@@ -171,6 +146,10 @@ void TangoEthernetLink::write (std::string command_to_send) throw (Tango::DevFa
description.c_str(), description.c_str(),
(const char*)"TangoEthernetLink::write"); (const char*)"TangoEthernetLink::write");
} }
if( argin )
{
delete [] argin;
}
} }
...@@ -189,7 +168,6 @@ std::string TangoEthernetLink::read (void) throw (Tango::DevFailed) ...@@ -189,7 +168,6 @@ std::string TangoEthernetLink::read (void) throw (Tango::DevFailed)
try try
{ {
dd_out = _ethernet_proxy->command_inout("Read"); dd_out = _ethernet_proxy->command_inout("Read");
dd_out >> response; dd_out >> response;
} }
...@@ -217,42 +195,10 @@ std::string TangoEthernetLink::read (void) throw (Tango::DevFailed) ...@@ -217,42 +195,10 @@ std::string TangoEthernetLink::read (void) throw (Tango::DevFailed)
std::string TangoEthernetLink::write_read (std::string command_to_send, size_t nbChar) throw (Tango::DevFailed) std::string TangoEthernetLink::write_read (std::string command_to_send, size_t nbChar) throw (Tango::DevFailed)
{ {
std::string resp; std::string resp;
write(command_to_send);
check_proxy(); //- sleep a little bit to let the adapter(RS232/485) to switch mode
if(!_is_ethernet_proxy_ok) omni_thread::sleep(0, 100000000); //100 milliseconds
return ""; return read();
Tango::DeviceData dd_in;
Tango::DevString argin = 0;
Tango::DeviceData dd_out;
std::string response("");
try
{
argin = new char [command_to_send.size() + 1];
strcpy(argin, command_to_send.c_str());
dd_in << argin;
dd_out = _ethernet_proxy->command_inout("WriteRead", dd_in);
dd_out >> response;
}
catch(Tango::DevFailed& df )
{
Tango::Except::re_throw_exception (df,
(const char*)"COMMUNICATION_ERROR",
(const char*)"Unable to perform a read operation",
(const char*)"TangoEthernetLink::read");
}
catch(...)
{
Tango::Except::throw_exception (
(const char*)"COMMUNICATION_ERROR",
(const char*)"Unable to perform a read operation",
(const char*)"TangoEthernetLink::read");
}
return response ;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment