可以清理损坏的堆吗?

Can a corrupted heap be cleaned up?

如果我破坏了我的堆,我可以事后清理它吗?如果是,如何?

堆损坏示例:

int *x = new int; // If we allocate memory wit new, we have to free it later.. 
x++;
*x = 1; // the heap is now corrupted

但是,调用free(x)delete x等会导致上面的代码崩溃。内存是否仍能以某种方式被释放,或者它是否已经坏到无可救药了?

If I corrupt my heap, can I clean it up afterwards?

不,你无法解决这个问题。基本上你的程序有未定义的行为堆损坏 是一些清理工具检测到的东西 运行 您的代码处于调试模式。

无法撤消 *x = 1; 或恢复之前驻留的值。


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?

破破烂烂