
calloc and free, msvc++ v5.0
I'm doing a conversion of my system from borland v4.53 to msvc. While
testing, using the debug version of the system as generated by msvc, I'm
receiving an assert error in free() (actually _free_dbg_lk()). A code snipet
from _free_dbg_lk() in dbgheap.c, where the assert is happening follows:
...
/* optionally reclaim memory */
if (!(_crtDbgFlag & _CRTDBG_DELAY_FREE_MEM_DF))
{
/* remove from the linked list */
if (pHead->pBlockHeaderNext)
{
pHead->pBlockHeaderNext->pBlockHeaderPrev =
pHead->pBlockHeaderPrev;
}
else
{
_ASSERTE(_pLastBlock == pHead);
_pLastBlock = pHead->pBlockHeaderPrev;
}
if (pHead->pBlockHeaderPrev)
{
pHead->pBlockHeaderPrev->pBlockHeaderNext =
pHead->pBlockHeaderNext;
}
else
{
==> assert fails here
==> _ASSERTE(_pFirstBlock == pHead);
_pFirstBlock = pHead->pBlockHeaderNext;
}
...
What I'm trying to do is free memory allocated to a struct that contained
structs whose memory has already been freed (successfully).
pHead->pBlockHeaderPrev is NULL and it should be.
When the space is calloc'd, _pFirstBlock's address wasn't the same as pHead
(32 byte difference). Why should it be the same now?
I don't know if this is something I should worry about. If anyone has any
ideas on how to go about fixing this or things to look at while debugging,
thanks.
--