Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A heap has been corrupted in various places through the code [closed]

i have this game of domino i created using CPP. While playing i'm getting this error:

Unhandled exception at 0x76FF5934 (ntdll.dll) in Domino.exe: 0xC0000374: A heap has been corrupted (parameters: 0x77011378).

Same error but the timing and the place in code it breaks is different, but the code it breaks on is always the same:

Stone* P = new Stone[numP];

This code is found in all sort of places, Stone is a class i created to represent a domino stone.

I have no idea what's wrong, i'm pretty sure it has something to do with memory but i have no idea why this line is causing problems, i'm not expecting you to tell me why it's happening since you can't see the full code but i hope you could try and help me with places to search for.

like image 355
Dorin Haliva Avatar asked Apr 13 '15 15:04

Dorin Haliva


People also ask

How can we stop heap corruption?

4 Answers. Show activity on this post. When using char* p , you're allocating p on the heap so you have to take care of deleting it at the end. Between the char *p and delete , in do some stuff with p , the code could throw an exception and p is leaked.

What causes heap corruption?

Heap corruption occurs when a program damages the allocator's view of the heap. The outcome can be relatively benign and cause a memory leak (where some memory isn't returned to the heap and is inaccessible to the program afterward), or it may be fatal and cause a memory fault, usually within the allocator itself.

How do I know if heap is corrupted?

Then you can sprinkle calls to CheckForHeapCorruption() throughout your code, so that when heap corruption occurs it will be detected at the next call to CheckForHeapCorruption() rather than some time later on.

How do you find the source of heap corruption?

Check for heap corruption Try using the Global Flags Utility (gflags.exe) or pageheap.exe. See /windows-hardware/drivers/debugger/gflags-and-pageheap.

What causes heap corruption in C++?

Heap corruption is generally not caused by the line of code where it is detected. It is likely that there is another place in your code where memory corruption is occurring which is only being detected when you attempt to allocate your Stone array.

Do heap corruption problems only surface when debugger is attached?

Only when a debugger is attached and the application verifier is enabled do the problems surface. The reason is simple. In a nondebugger, non–Application Verifier run, the heap corruption still occurs but might not have enough time to surface in the form of an access violation.

How do I know if my heap is corrupt?

Typically, access violations occurring in the heap manager are good indicators that a heap corruption has occurred. Backtracking the source of the corruption from this location can be an excruciatingly difficult process that should be avoided at all costs.

Why doesn't heap corruption happen in non-application verifier tests?

The reason is simple. In a nondebugger, non–Application Verifier run, the heap corruption still occurs but might not have enough time to surface in the form of an access violation. Say that the test runs through scenarios A, B, and C, and the heap corruption occurs in scenario C.


2 Answers

Heap corruption is generally not caused by the line of code where it is detected. It is likely that there is another place in your code where memory corruption is occurring which is only being detected when you attempt to allocate your Stone array. Check for buffer overruns and other places where you are writing to dynamically allocated memory.

like image 72
Qartar Avatar answered Oct 30 '22 20:10

Qartar


Keep in mind that where ever the debugger stops only tells you where the damage was detected, never where the damage was done. So, i would step through your code and find what is going on with your Stone class. Its highly likely that there may be a flaw in your class structure. If the class isnt too big, post it and maybe it can be diagnosed?

like image 27
Javia1492 Avatar answered Oct 30 '22 20:10

Javia1492