我试图弄清楚是什么导致 Valgrind 警告一些“仍然可以到达”的块。我查看了我的代码,找不到任何 free() 丢失。我尝试使用 --leak-check=yes --show-reachable=yes 选项运行,这是输出示例:
==2999== 616 bytes in 7 blocks are still reachable in loss record 8 of 9
==2999== at 0xD9C3: calloc (vg_replace_malloc.c:597)
==2999== by 0x3188FA: _xpc_calloc (in /usr/lib/system/libxpc.dylib)
==2999== by 0x3191D4: _xpc_base_create (in /usr/lib/system/libxpc.dylib)
==2999== by 0x31FBEA: xpc_string_create (in /usr/lib/system/libxpc.dylib)
==2999== by 0x31EDFD: xpc_dictionary_set_string (in /usr/lib/system/libxpc.dylib)
==2999== by 0x320E8C: _libxpc_initializer (in /usr/lib/system/libxpc.dylib)
==2999== by 0x1BE7D: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==2999== by 0x7FFF5FC0FDA5: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==2999== by 0x7FFF5FC0FAF1: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==2999== by 0x7FFF5FC0D2E3: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==2999== by 0x7FFF5FC0D27C: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==2999== by 0x7FFF5FC0E0B6: ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==2999== 4,096 bytes in 1 blocks are still reachable in loss record 9 of 9
==2999== at 0xC713: malloc (vg_replace_malloc.c:274)
==2999== by 0x17F3F7: __smakebuf (in /usr/lib/system/libsystem_c.dylib)
==2999== by 0x175D19: __swsetup (in /usr/lib/system/libsystem_c.dylib)
==2999== by 0x1766C3: __vfprintf (in /usr/lib/system/libsystem_c.dylib)
==2999== by 0x17618D: vfprintf_l (in /usr/lib/system/libsystem_c.dylib)
==2999== by 0x17F2CF: printf (in /usr/lib/system/libsystem_c.dylib)
==2999== by 0x100003D21: printEstBasica (mod_dados.c:100)
==2999== by 0x100001635: main (mod_main.c:179)
我所理解的行要么是指“打印”功能(如 printEstBasica),在其上我只使用 printf 或 fprintf ......其他的我不知道它们是什么......我在其他帖子上读到人们说它可能指的是编译器使用的附加信息..但我不确定。有一件事让我想到:我在不同的数据集(由程序处理)上运行了 valgrind,具有不同的大小,并且仍然可以访问的字节数总是相同的。
提前致谢!