From 8df1106957062c03e8e5aef2fda091ad04c53512 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 6 May 2011 09:22:17 +0000 Subject: [PATCH] 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. --- applications/present3D/Cluster.h | 22 ++++++++++++++++------ applications/present3D/present3D.cpp | 6 +++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/applications/present3D/Cluster.h b/applications/present3D/Cluster.h index c3db10b62..4fb4176b5 100644 --- a/applications/present3D/Cluster.h +++ b/applications/present3D/Cluster.h @@ -172,13 +172,11 @@ class DataConverter _numBytes = numBytes; } - char* _startPtr; - char* _endPtr; - unsigned int _numBytes; - bool _swapBytes; + ~DataConverter() + { + delete [] _startPtr; + } - char* _currentPtr; - void reset() { _currentPtr = _startPtr; @@ -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; }; diff --git a/applications/present3D/present3D.cpp b/applications/present3D/present3D.cpp index 079f769f2..82f22ca2a 100644 --- a/applications/present3D/present3D.cpp +++ b/applications/present3D/present3D.cpp @@ -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()"<