Free Heap block modified after it was freed  
Author Message
Deeps_123





PostPosted: Visual C++ Language, Free Heap block modified after it was freed Top

I have developed an MFC application usin VC6. In this application I am allocating about 4kb of memory using new operator and deleting it using delete operator. But when i again use the new operator to allocate some more memory than this error is coming. If i remove the delete operator code than this error does not come but i dont want this because than there would be memory leaks in my code. Please help me out................ Any kind of help would be appreciated.

Visual C++7  
 
 
einaros





PostPosted: Visual C++ Language, Free Heap block modified after it was freed Top

The problem may be that you are writing to a pointer after it has been free'd, if you're running a debug build application, such out-of-bounds heap modifications will not be detected until the area is once again allocated. Are you absolutely sure you're not doing anything like that

Also, see to it that you're using delete[] to free arrays, and delete to free single instances. new[] => delete[], new => delete, that's the law :)



 
 
Brian Kramer





PostPosted: Visual C++ Language, Free Heap block modified after it was freed Top

If the CRT gives an assertion that reveals the address where the memory overrun occured, you can set a memory breakpoint on that address and run again. (Actually, you should make this breakpoint after entering your main entry point). The de**** should trap for writes to this invalid memory address and reveal the cause.
 
 
Deeps_123





PostPosted: Visual C++ Language, Free Heap block modified after it was freed Top

I searched on the msdn and found that the memory that is freed last is the first available memory for the allocation. I have found the workaround by not initialising it as a pointer but i really want to know the proper solution cos i am still facing the problem the only difference is now it comes once in 100 times. Please help me out.
 
 
einaros





PostPosted: Visual C++ Language, Free Heap block modified after it was freed Top

Have you tried applying the debugging technique provided by Brian

 
 
Brian Kramer





PostPosted: Visual C++ Language, Free Heap block modified after it was freed Top

Searching the web to determine how a memory corruption occurred is a lot like searching the web to figure out how you tripped on the sidewalk. The de**** is your friend on this one. :)