Skip to content
Snippets Groups Projects
Commit da49c3ea authored by Simon Ottenhaus's avatar Simon Ottenhaus
Browse files

Fixed Memory Leak

parent 10fde8e4
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@
#include <stdexcept>
#include <boost/format.hpp>
#include <vector>
#include <Core/core/logging/Logging.h>
struct Response {
public:
......@@ -44,11 +45,12 @@ public:
//std::strstream strStream;
//strStream << "Command not successful: " << status_to_str( status );
//throw std::runtime_error(strStream.str());
std::cerr << " status != E_SUCCESS" << std::endl;
std::stringstream ss;
ss << " status != E_SUCCESS";
for(int i=0; i<(int)len; i++){
std::cerr << boost::format("%02X ") % (int)data[i];
ss << boost::format("%02X ") % (int)data[i];
}
std::cerr << std::endl;
ARMARX_ERROR_S << ss.str();
throw TransmissionException(str(boost::format("Command not successful: %1% (0x%2$02X)") % status_to_str( status ) % status));
}
}
......
......@@ -87,11 +87,13 @@ PeriodicFrameData TactileSensor::getPeriodicFrameData(Response *response)
int count = (response->len - offset) / 2;
int i;
short* data = new short[ count ];
boost::shared_ptr<std::vector<short> > data;
data.reset(new std::vector<short>(count, 0));
//short* data = new short[ count ];
for(i = 0; i < count; i++)
{
short value = response->getShort(i*2 + offset);
data[i] = value;
(*data)[i] = value;
}
return PeriodicFrameData(data, count, timestamp);
}
......@@ -105,11 +107,12 @@ FrameData TactileSensor::getFrameData(Response *response)
int count = (response->len - offset) / 2;
int i;
short* data = new short[ sizeof(short) * count ];
boost::shared_ptr<std::vector<short> > data;
data.reset(new std::vector<short>(count, 0));
for(i = 0; i < count; i++)
{
short value = response->getShort(i*2 + offset);
data[i] = value;
(*data)[i] = value;
}
return FrameData(data, count);
}
......
......@@ -41,19 +41,19 @@ typedef struct
struct FrameData
{
public:
FrameData(short *data, int count)
FrameData(boost::shared_ptr<std::vector<short> > data, int count)
: data(data), count(count)
{}
short *data;
boost::shared_ptr<std::vector<short> > data;
int count;
};
struct PeriodicFrameData
{
public:
PeriodicFrameData(short *data, int count, unsigned int timestamp)
PeriodicFrameData(boost::shared_ptr<std::vector<short> > data, int count, unsigned int timestamp)
: data(data), count(count), timestamp(timestamp)
{}
short *data;
boost::shared_ptr<std::vector<short> > data;
int count;
unsigned int timestamp;
};
......
......@@ -98,7 +98,7 @@ void WeissHapticSensor::frameAcquisitionTaskLoop()
{
for (int x = 0; x < mi.res_x; x++)
{
short val = data.data[y * mi.res_x + x];
short val = (*data.data)[y * mi.res_x + x];
(*matrix)(y, x) = val;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment