在Xcode中打开了一些调试选项后,我得到了以下输出:
GuardMalloc[Roadcast-4010]: free: magic is 0x0000090b, not 0xdeadbeef.
GuardMalloc[Roadcast-4010]: free: header magic value at 0x43f49bf0, for block 0x43f49c00-0x43f50000, has been trashed by a buffer underrun.
GuardMalloc[Roadcast-4010]: Try running with MALLOC_PROTECT_BEFORE to catch this error immediately as it happens.
如何开启MALLOC_PROTECT_BEFORE
?
更新:
在Mac Developer Library > Guard_Malloc中,文档详细说明了MALLOC_PROTECT_BEFORE
的作用:
libgmalloc的行为可以通过多个额外的环境变量进行更改:
MALLOC_PROTECT_BEFORE
如果设置了此标志,则libgmalloc将更努力地检测缓冲区下溢。具体来说,libgmalloc将分配的缓冲区的开始放置在虚拟内存页面的开头,然后在前面保护该页面。缓冲区下溢会导致错误。如果没有设置此变量,则行为是将缓冲区的末尾放置在分配的最后一页的末尾,然后保护其后面的页面。