Is there a way in VC++/MFC to determine if memory belonging to a pointer has
been deleted in debug and release versions?
I have an application with over 50 megs worth of code. Not something easy
to debug in some spaghetti code places.
We have several pointers to a place of memory being passed back and forth
through so many functions. I have an intermittent GPF. At some point, the
memory is being deleted (using delete), and then we try to access it again
at a later point.
The problem is that since it is not reproducible every time.
It was suggested to me from a newsgroup that I find all occurrences of a "delete" or "free" statement and assign the pointer to NULL at that time.
This does not help for the following reason:
Let's say I have four different pointers to the same memory that have been
set in different functions because they were passed as parameters:
pTemp = (CBlob *) new char;
pNewObj = pTemp
pOldObj = pTemp
pSameObj = pOldObj
If I delete pOldObj, I can set pOldObj to 0. However, I cannot set the rest
of the pointers to 0 if I don't know that they are pointing to the same
The only way to fix this is to track down the source of the bug (keep in
mind, it's intermittent and this is spaghetti code) or determine if the
memory for a pointer has not been deleted.