这是我编写的代码:
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;
}
我正在另一个类中创建上述类的对象:
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();
}
在 Coverity 和 C++ Memory Validator 中,我在 PerChannel 的构造函数中遇到资源泄漏错误。
我不确定这里有什么问题?
非常感谢您的帮助。
钦坦