GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Sep-2009, 07:29
dpreznik dpreznik is offline
New Member
 
Join Date: Sep 2009
Posts: 7
dpreznik is on a distinguished road

CArray destruction problem


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:
Help with Code Tags
C++ Syntax (Toggle Plain Text)

CPP / C++ / C Code:
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.
Last edited by LuciWiz : 15-Sep-2009 at 07:36. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache Web Server newbie problem niss3 Apache Web Server Forum 1 13-Apr-2009 19:38
Torrents Download Problem chandeep Computer Software Forum - Linux 7 09-Oct-2006 23:37
Runtime Problem involving "printf" in C Program supamakia C Programming Language 2 09-Oct-2005 11:09
a significant problem after installing Xp mohammad Computer Software Forum - Windows 10 09-Aug-2005 08:03

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:27.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.