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.
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.
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.
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.
Check for heap corruption Try using the Global Flags Utility (gflags.exe) or pageheap.exe. See /windows-hardware/drivers/debugger/gflags-and-pageheap.
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.
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.
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.
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.
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With