Sign in to follow this  
monkeyboi

Something About Heap Allocation

Recommended Posts

Firstly sorry about the ambiguous title, I really don't know what causes my problem.

Recently I have been doing memory leak detection for my program, however after some work I got this assertion poping out shown:


Windows has triggered a breakpoint in LumPy.exe.

This may be due to a corruption of the heap, which indicates a bug in LumPy.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while LumPy.exe has focus.

The output window may have more diagnostic information.

In the output window there are


'LumPy.exe': Loaded 'C:\Windows\SysWOW64\oleacc.dll'
HEAP[LumPy.exe]: HEAP: Free Heap block 367578 modified at 3675b0 after it was freed
Windows has triggered a breakpoint in LumPy.exe.

And then it will stop at the line of return HeapAlloc(_crtheap, 0, size ? size : 1);


#ifdef _WIN64
return HeapAlloc(_crtheap, 0, size ? size : 1);
#else /* _WIN64 */
if (__active_heap == __SYSTEM_HEAP) {
return HeapAlloc(_crtheap, 0, size ? size : 1); //stop here//
} else
if ( __active_heap == __V6_HEAP ) {
if (pvReturn = V6_HeapAlloc(size)) {
return pvReturn;
}
}

If press the continue button it could run fine. But I am afraid this will be a really big potential problem in the future. So anyone could tell me where is wrong when this kind of problems happen or give me any idea how to debug this problem. Thanks advanced.

Jerry

Share this post


Link to post
Share on other sites
You're accessing memory that has already been deleted. Basically:
[code]
int* ptr = new int;
int* p = ptr;

*ptr = 5;
delete ptr;

*p = 3; // Crash!
[/code]

If you want to know where it is happening, then just look at the call stack. :)
If you want to know why it is happening, then it will take some work...

Whenever you make a reference to an object via a pointer, you will need to keep in mind as to who owns the object, when and where the object should be deleted, and ensure that there are no dangling references after deleting the object. Edited by fastcall22

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this