I am facing a problem with a CArray. I have a class member of type CArray<MyType, MyType&> m_MyArray;
When the object is destroyed, of course the destructor of CArray<MyType, MyType&> is called.
Here is the destructor:
template<class TYPE, class ARG_TYPE>
CArray<TYPE, ARG_TYPE>::~CArray()
{
ASSERT_VALID(this);
if (m_pData != NULL)
{
for( int i = 0; i < m_nSize; i++ )
(m_pData + i)->~TYPE();
delete[] (BYTE*)m_pData;
}
}
The debugger shows my m_pData to be 0X00000005.
As we can see from the code above, delete[] is called on this pointer because it is not NULL. The delete[] calls delete, which calls _free_dbg(), which calls CheckBytes(), where the pointer is passed already as 0X00000000 (bad ptr). On attempt to dereference this pointer ( if (*pb++ != bCheck)), a crash happens.
Can somebody help me solve this problem, please?
Thanks.