HEAP error: Free heap block xxx mdofied at xxx 
Author Message
 HEAP error: Free heap block xxx mdofied at xxx

Hi!

When I delete an object allocated on the heap I get a "user breakpoint" (int
3) and the code stops somewhere in ntdll. In the output window I see the
message:

HEAP[TaskTest.exe]: HEAP: Free Heap block bb6148 modified at bb6190 after it
was freed

OK, it sounds clear enough, but I don't see how this could happen, because
it happens when I delete the object (before it returns from delete this) and
I don't have any change to still modify its memory. If I hit F5 the program
continues to run normally.

Did anybody see this message and knows what it means? When it usually
appears, what can you do about it? Could it be because I use two threads and
pass pointers between them? (I think that objects are allocated and freed on
the same thread, still).

Thanks,
iuli



Sat, 31 Jan 2004 17:40:16 GMT  
 HEAP error: Free heap block xxx mdofied at xxx
you are probably declaring a pointer,

assigning memory with new (char* myChars = new char[50];)

then using = to move the pointer (myChars = "myString";)

then deleting (delete [] myChars)

thus causing the error

if your doing something like this, don't ;)

seriously, just look around your news for assigns, or search for the
variable and look to see if your using = someplace, its an easy mistake to
make if your not paying attention.

marc


Quote:
> Hi!

> When I delete an object allocated on the heap I get a "user breakpoint"
(int
> 3) and the code stops somewhere in ntdll. In the output window I see the
> message:

> HEAP[TaskTest.exe]: HEAP: Free Heap block bb6148 modified at bb6190 after
it
> was freed

> OK, it sounds clear enough, but I don't see how this could happen, because
> it happens when I delete the object (before it returns from delete this)
and
> I don't have any change to still modify its memory. If I hit F5 the
program
> continues to run normally.

> Did anybody see this message and knows what it means? When it usually
> appears, what can you do about it? Could it be because I use two threads
and
> pass pointers between them? (I think that objects are allocated and freed
on
> the same thread, still).

> Thanks,
> iuli



Sun, 01 Feb 2004 02:48:44 GMT  
 HEAP error: Free heap block xxx mdofied at xxx
Interesting. I've never seen that error message. However this program
will produce it (modified from a program designed to produce different
error messages).

The trick is that the first allocation is modified after it is freed, then the
call to GlobalAlloc() for the second function checks the freed memory
from the first allocation and warns that it has been modified.

Try pageheap, purify, boundschecker or other tools to track down
this bug in your code.

const int k_allocSize = 10000;

void Problem1()
{
 char* ptr = (char*)GlobalAlloc(GMEM_FIXED, k_allocSize);
 // Oops - bad write.
// ptr[k_allocSize] = 0;
 // The Win2K memory allocation system will detect the bad
 // write when the memory is freed if you are running under
 // a de{*filter*} and will trigger a user breakpoint.
 GlobalFree(ptr);
 ptr[8] = 0;

Quote:
}

void Problem2()
{
 char* ptr = (char*)GlobalAlloc(GMEM_FIXED, k_allocSize);
 GlobalFree(ptr);
 // The Win2K memory allocation system will detect double
 // frees and will trigger a user breakpoint.
 GlobalFree(ptr);

Quote:
}

int main(int argc, char*argv[])
{
 Problem1();
 Problem2();
 return 0;
Quote:
}

> Hi!

> When I delete an object allocated on the heap I get a "user breakpoint" (int
> 3) and the code stops somewhere in ntdll. In the output window I see the
> message:

> HEAP[TaskTest.exe]: HEAP: Free Heap block bb6148 modified at bb6190 after it
> was freed

> OK, it sounds clear enough, but I don't see how this could happen, because
> it happens when I delete the object (before it returns from delete this) and
> I don't have any change to still modify its memory. If I hit F5 the program
> continues to run normally.

> Did anybody see this message and knows what it means? When it usually
> appears, what can you do about it? Could it be because I use two threads and
> pass pointers between them? (I think that objects are allocated and freed on
> the same thread, still).

> Thanks,
> iuli



Sun, 01 Feb 2004 13:19:21 GMT  
 HEAP error: Free heap block xxx mdofied at xxx
Thank you all for your attention.

I finally discovered the problem: I was using a Dialog driven by a COM
object, and I wanted to delete the object (with the dialog) (like any COM
object) when there are no references to it. The problem was that I forgot to
AddRef the dialog, and the only reference was that from the external COM
client, which released it when I pressed the OK button. That will decrement
my reference cout to 0, triggering a "delete this". Bad idea, because this
was all done in "DoModal", and after my deleteion the code returned to MFC
code, which modifyed some member data in my deallocated object. Strange I
didn't get an Access Violation (until I used pageheap :)

iuli


Quote:
> Hi!

> When I delete an object allocated on the heap I get a "user breakpoint"
(int
> 3) and the code stops somewhere in ntdll. In the output window I see the
> message:

> HEAP[TaskTest.exe]: HEAP: Free Heap block bb6148 modified at bb6190 after
it
> was freed

> OK, it sounds clear enough, but I don't see how this could happen, because
> it happens when I delete the object (before it returns from delete this)
and
> I don't have any change to still modify its memory. If I hit F5 the
program
> continues to run normally.

> Did anybody see this message and knows what it means? When it usually
> appears, what can you do about it? Could it be because I use two threads
and
> pass pointers between them? (I think that objects are allocated and freed
on
> the same thread, still).

> Thanks,
> iuli



Sun, 01 Feb 2004 19:59:37 GMT  
 HEAP error: Free heap block xxx mdofied at xxx
Unfortunately an access violation due to modifying memory after it is
freed is very rare. Unless you allocate a huge chunk of memory, it is
probably sharing a page with other allocations and therefore has to stay
mapped in after it is freed. Even if it isn't sharing a page with any
other allocations, it is usually too much hassle for the memory system
to return the memory to the OS - instead it just recycles it for later
allocations.

It's possible to make a system such that each allocation goes on a
separate page (which pageheap does) and so that pages are released
back to the OS as soon as you free the memory, and aren't reused
for a long time (which pageheap apparently doesn't do).

pageheap is great, but it could use a bit of work.

Quote:

> Thank you all for your attention.

> I finally discovered the problem: I was using a Dialog driven by a COM
> object, and I wanted to delete the object (with the dialog) (like any COM
> object) when there are no references to it. The problem was that I forgot to
> AddRef the dialog, and the only reference was that from the external COM
> client, which released it when I pressed the OK button. That will decrement
> my reference cout to 0, triggering a "delete this". Bad idea, because this
> was all done in "DoModal", and after my deleteion the code returned to MFC
> code, which modifyed some member data in my deallocated object. Strange I
> didn't get an Access Violation (until I used pageheap :)

> iuli



> > Hi!

> > When I delete an object allocated on the heap I get a "user breakpoint"
> (int
> > 3) and the code stops somewhere in ntdll. In the output window I see the
> > message:

> > HEAP[TaskTest.exe]: HEAP: Free Heap block bb6148 modified at bb6190 after
> it
> > was freed

> > OK, it sounds clear enough, but I don't see how this could happen, because
> > it happens when I delete the object (before it returns from delete this)
> and
> > I don't have any change to still modify its memory. If I hit F5 the
> program
> > continues to run normally.

> > Did anybody see this message and knows what it means? When it usually
> > appears, what can you do about it? Could it be because I use two threads
> and
> > pass pointers between them? (I think that objects are allocated and freed
> on
> > the same thread, still).

> > Thanks,
> > iuli



Wed, 04 Feb 2004 13:23:39 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. HEAP[dllhost.exe]: HEAP: Free Heap block 1e32c28 modified at 1e32dc4 after it was freed

2. Heap errors when stressing Automation, _bstr_t, and watching heap blocks

3. using the string xxx or XXX as a means of terminating the program

4. #if XXX when XXX is not defined?

5. Free Heap block

6. "Heap block" error

7. "Heap block" error

8. Free Heap Debug error

 

 
Powered by phpBB® Forum Software