Fixed Coverity reported issue.

CID 11388: Resource leak in object (CTOR_DTOR_LEAK)
Allocating memory by calling "new char[numBytes]".
Assigning: "this->_startPtr" = "new char[numBytes]".
The constructor allocates field "_startPtr" of "struct DataConverter" but there is no destructor.
Assigning: "this->_currentPtr" = "new char[numBytes]".
The constructor allocates field "_currentPtr" of "struct DataConverter" but there is no destructor.
This commit is contained in:
Robert Osfield 2011-05-06 09:22:17 +00:00
parent e6217e3f82
commit 8df1106957
2 changed files with 19 additions and 9 deletions

View File

@ -172,12 +172,10 @@ class DataConverter
_numBytes = numBytes;
}
char* _startPtr;
char* _endPtr;
unsigned int _numBytes;
bool _swapBytes;
char* _currentPtr;
~DataConverter()
{
delete [] _startPtr;
}
void reset()
{
@ -327,6 +325,18 @@ class DataConverter
void write(CameraPacket& cameraPacket);
void read(CameraPacket& cameraPacket);
char* startPtr() { return _startPtr; }
unsigned int numBytes() { return _numBytes; }
protected:
char* _startPtr;
char* _endPtr;
unsigned int _numBytes;
bool _swapBytes;
char* _currentPtr;
};

View File

@ -918,15 +918,15 @@ int main( int argc, char **argv )
scratchPad.reset();
scratchPad.read(cp);
bc.setBuffer(scratchPad._startPtr, scratchPad._numBytes);
bc.setBuffer(scratchPad.startPtr(), scratchPad.numBytes());
std::cout << "bc.sync()"<<scratchPad._numBytes<<std::endl;
std::cout << "bc.sync()"<<scratchPad.numBytes()<<std::endl;
bc.sync();
}
else if (P3DApplicationType==SLAVE)
{
rc.setBuffer(scratchPad._startPtr, scratchPad._numBytes);
rc.setBuffer(scratchPad.startPtr(), scratchPad.numBytes());
rc.sync();