calloc and free, msvc++ v5.0 
Author Message
 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.

--



Sat, 01 Jul 2000 03:00:00 GMT  
 calloc and free, msvc++ v5.0

I've seen this happen under a couple of circumstances: 1) errors in my
program that were clobbering the heap and 2) mismatched heap functions (some
modules built with DLL version others with static or some modules built
debug and others not).

--



Sun, 02 Jul 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. calloc and free, msvc++ v5.0

2. MSVC V5.0 Floating-point Optimization problem

3. Problem with calloc (MSVC

4. Problem with calloc (MSVC 1.51, Win 3.11)

5. Problem with calloc (MSVC

6. Wanted: Free STL that works well with MSVC 4.2

7. Override malloc,calloc,realloc and free?

8. calloc() & free()

9. freeing the memory allocated by calloc

10. Is this Wrong? (calloc/free question)

11. doubt - freeing the memory allocated by calloc

12. calloc and free

 

 
Powered by phpBB® Forum Software