Here is the code that I have written:
class sCircBuffer
{
public:
sCircBuffer(void);
~sCircBuffer(void);
double *Data;
int Size;
bool Init(int SizeBuffer);
bool Delete();
}
sCircBuffer :: sCircBuffer(void) //Constructor
{
Data=NULL; //Initialize input circular buffer
}
sCircBuffer :: ~sCircBuffer(void) //Destructor
{
delete [] Data; //Initialize input circular buffer
Data=NULL;
}
bool sCircBuffer :: Init(int SizeBuffer)
{
delete [] Data; //Initialize input circular buffer
Data=new double [SizeBuffer]; //Initialize input circular buffer
Size=SizeBuffer;
for (int i=0; i<Size; i++)
Data[i]=0;
return true;
}
bool sCircBuffer :: Delete()
{
delete [] Data; //Initialize input circular buffer
Data=NULL;
return true;
}
I am creating an object of above class in another class:
class PerChannel
{
public:
PerChannel();
~PerChannel();
sCircBuffer m_InputDataRaw;
}
PerChannel :: PerChannel()
{
m_InputDataRaw.Init(MAX_NUM_TO_FETCH); // MAX_NUM_TO_FETCH = 1000
}
PerChannel :: ~PerChannel()
{
m_InputDataRaw.Delete();
}
In Coverity and C++ Memory Validator, I am getting resource leak error in the constructor of PerChannel.
I am not sure what is wrong here?
Your help is really appreciated.
Chintan