0

I am running my program though valgrind, but it appears it is generating errors caused by the tool itself? All my errors look like the following, but from reading through other posts, it seems that usually the at line tells you where in your program the offending malloc occurs, but all my at lines are coming from valgrind. Are these legit errors in my program?

==10551== 32,808 (24 direct, 32,784 indirect) bytes in 1 blocks are definitely lost in loss     record 840 of 843
==10551==    at 0x54D7: malloc_zone_malloc (in     /usr/local/Cellar/valgrind/3.8.1/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==10551==    by 0x7C5171: NXCreateMapTableFromZone (in /usr/lib/libobjc.A.dylib)
==10551==    by 0x7C4722: _read_images (in /usr/lib/libobjc.A.dylib)
==10551==    by 0x7C39EB: map_images_nolock (in /usr/lib/libobjc.A.dylib)
==10551==    by 0x7C34F3: map_images (in /usr/lib/libobjc.A.dylib)
==10551==    by 0x7FFF5FC04936: dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)) (in /usr/lib/dyld)
==10551==    by 0x7FFF5FC0467C: dyld::registerImageStateBatchChangeHandler(dyld_image_states, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)) (in /usr/lib/dyld)
==10551==    by 0xA99ED9: dyld_register_image_state_change_handler (in /usr/lib/system/libdyld.dylib)
==10551==    by 0x7C204C: _objc_init (in /usr/lib/libobjc.A.dylib)
==10551==    by 0x6BB27: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==10551==    by 0x7FFF5FC13377: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==10551==    by 0x7FFF5FC13761: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==10551== 

I used homebrew to install valgrind. It probably has something to do with this error:

==10551== WARNING: Support on MacOS 10.8 is experimental and mostly broken.
==10551== WARNING: Expect incorrect results, assertions and crashes.

but I just want to make sure (by someone who has used this before) that these errors are not coming from my program. (I am on 10.8).

4

2 回答 2

0

错误检查工具检测系统库中的许多问题,例如 C 库,这些库预装在您的操作系统中。你不能轻易地修复这些,但你不想看到这些错误(是的,有很多!)所以 Valgrind 读取错误列表以在启动时抑制。构建系统时,./configure 脚本会创建一个默认抑制文件。

您可以在闲暇时修改并添加到抑制文件,或者更好地编写自己的文件。允许多个抑制文件。如果您的项目的一部分包含您不能或不想修复的错误,但您不想不断地被提醒它们,这将非常有用。

注意:到目前为止,添加抑制的最简单方法是使用核心命令行选项中描述的 --gen-suppressions=yes 选项。这会自动生成抑制。但是,为了获得最佳结果,您可能需要手动编辑 --gen-suppressions=yes 的输出,在这种情况下,建议通读本节。

每个要抑制的错误都进行了非常具体的描述,以最大限度地减少抑制指令无意中抑制了一堆您确实想看到的类似错误的可能性。抑制机制旨在允许精确而灵活地指定要抑制的错误。

于 2013-12-15T11:52:47.610 回答
0

Valgrind 自己替换了库函数分配和释放内存的默认实现(malloc()、calloc()、realloc()、free() 是最重要的),以跟踪对它们的调用并进行簿记。回溯显示了 malloc() 调用的调用堆栈,该调用分配了从未释放过的内存。所以问题不在于 malloc() 本身——而在于调用 malloc() 而没有相应的 free() 的代码。

于 2013-10-22T20:09:21.047 回答