If I corrupt my heap, can I clean it up afterwards? If yes, how?
Example for a heap corruption:
int *x = new int; // If we allocate memory wit new, we have to free it later..
x++;
*x = 1; // the heap is now corrupted
However, calling free(x)
, delete x
etc. will crash above's code. Can the memory still be somehow deallocated or is it already broken beyond hope?
If I corrupt my heap, can I clean it up afterwards?
No you can't fix this. Basically your program has undefined behavior. A heap corruption is something detected by some sanitizer tools running your code in debug mode.
There's no way to undo *x = 1;
or to restore the value that was residing there before.
However, calling free(x), delete x etc. will crash above's code.
Sure, you're trying to free something you never allocated.
Can the memory still be somehow deallocated or is it already broken beyond hope?
It's broken beyond any hope.