作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用一些直接从磁盘文件读取的原始代码。整个开始代码中只有一个 malloc 调用(我检查过这不是问题)。在我自己的代码中,我不使用 malloc、strdup 或任何其他堆调用。然而,运行 valgrind 并进行完整的泄漏检查我仍然得到(如下)。
我无法识别它显示的任何文件。我在带有 Lion 的 Mac OSX 上运行此程序。这是否可能是系统库的问题,或者是他们解决此问题的另一种方法。我知道有些人会说拥有可访问的内存是可以的,但我很好奇为什么任何内存仍然是可访问的。
-
-90966-- REDIR: 0x3a46c7 (free) redirected to 0x55b8 (free)
==90966==
==90966== HEAP SUMMARY:
==90966== in use at exit: 6,383 bytes in 33 blocks
==90966== total heap usage: 34 allocs, 1 frees, 6,899 bytes allocated
==90966==
==90966== Searching for pointers to 33 not-freed blocks
==90966== Checked 684,888 bytes
==90966==
==90966== 8 bytes in 1 blocks are still reachable in loss record 1 of 9
==90966== at 0x5237: malloc (in /usr/local/Cellar/valgrind/3.8.1/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==90966== by 0x7FFF5FC11C2A: malloc (in /usr/lib/dyld)
==90966== by 0x7FFF5FC19C4E: operator new(unsigned long) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0817E: std::vector<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), std::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)> >::_M_insert_aux(__gnu_cxx::__normal_iterator<char const* (**)(dyld_image_states, unsigned int, dyld_image_info const*), std::vector<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), std::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)> > >, char const* (* const&)(dyld_image_states, unsigned int, dyld_image_info const*)) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC08260: std::vector<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), std::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)> >::insert(__gnu_cxx::__normal_iterator<char const* (**)(dyld_image_states, unsigned int, dyld_image_info const*), std::vector<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), std::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)> > >, char const* (* const&)(dyld_image_states, unsigned int, dyld_image_info const*)) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC054FA: dyld::registerImageStateBatchChangeHandler(dyld_image_states, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)) (in /usr/lib/dyld)
==90966== by 0x2C1ACB: dyld_register_image_state_change_handler (in /usr/lib/system/libdyld.dylib)
==90966== by 0x2C2ACB: _dyld_initializer (in /usr/lib/system/libdyld.dylib)
==90966== by 0x1CFE73: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==90966== by 0x7FFF5FC0FDA5: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0FAF1: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0D2E3: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966==
==90966== 87 bytes in 7 blocks are still reachable in loss record 2 of 9
==90966== at 0x5237: malloc (in /usr/local/Cellar/valgrind/3.8.1/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==90966== by 0x342358: strdup (in /usr/lib/system/libsystem_c.dylib)
==90966== by 0x4E7802: _xpc_strdup (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4EDCCF: _xpc_dictionary_insert (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4EDE0E: xpc_dictionary_set_string (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4EFE8C: _libxpc_initializer (in /usr/lib/system/libxpc.dylib)
==90966== by 0x1CFE7D: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==90966== by 0x7FFF5FC0FDA5: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0FAF1: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0D2E3: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0D27C: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0E0B6: ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966==
==90966== 88 bytes in 1 blocks are still reachable in loss record 3 of 9
==90966== at 0x5237: malloc (in /usr/local/Cellar/valgrind/3.8.1/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==90966== by 0x2CA9B0: get_or_create_key_element (in /usr/lib/system/libkeymgr.dylib)
==90966== by 0x2CABC9: _keymgr_get_and_lock_processwide_ptr_2 (in /usr/lib/system/libkeymgr.dylib)
==90966== by 0x2CAC36: __keymgr_initializer (in /usr/lib/system/libkeymgr.dylib)
==90966== by 0x1CFE6E: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==90966== by 0x7FFF5FC0FDA5: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0FAF1: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0D2E3: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0D27C: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0E0B6: ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC034B7: dyld::initializeMainExecutable() (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0760A: dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**) (in /usr/lib/dyld)
==90966==
==90966== 136 bytes in 1 blocks are still reachable in loss record 4 of 9
==90966== at 0x58DE: calloc (in /usr/local/Cellar/valgrind/3.8.1/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==90966== by 0x4E78FA: _xpc_calloc (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4E81D4: _xpc_base_create (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4F1C32: _xpc_domain_create (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4EFF1E: _libxpc_initializer (in /usr/lib/system/libxpc.dylib)
==90966== by 0x1CFE7D: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==90966== by 0x7FFF5FC0FDA5: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0FAF1: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0D2E3: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0D27C: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0E0B6: ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC034B7: dyld::initializeMainExecutable() (in /usr/lib/dyld)
==90966==
==90966== 224 bytes in 7 blocks are still reachable in loss record 5 of 9
==90966== at 0x5237: malloc (in /usr/local/Cellar/valgrind/3.8.1/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==90966== by 0x4E793D: _xpc_malloc (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4EDCB4: _xpc_dictionary_insert (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4EDE0E: xpc_dictionary_set_string (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4EFE8C: _libxpc_initializer (in /usr/lib/system/libxpc.dylib)
==90966== by 0x1CFE7D: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==90966== by 0x7FFF5FC0FDA5: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0FAF1: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0D2E3: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0D27C: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0E0B6: ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC034B7: dyld::initializeMainExecutable() (in /usr/lib/dyld)
==90966==
==90966== 520 bytes in 7 blocks are still reachable in loss record 6 of 9
==90966== at 0x5237: malloc (in /usr/local/Cellar/valgrind/3.8.1/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==90966== by 0x342358: strdup (in /usr/lib/system/libsystem_c.dylib)
==90966== by 0x4E7802: _xpc_strdup (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4EEBF5: xpc_string_create (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4EDDFD: xpc_dictionary_set_string (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4EFE8C: _libxpc_initializer (in /usr/lib/system/libxpc.dylib)
==90966== by 0x1CFE7D: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==90966== by 0x7FFF5FC0FDA5: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0FAF1: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0D2E3: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0D27C: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0E0B6: ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966==
==90966== 608 bytes in 1 blocks are still reachable in loss record 7 of 9
==90966== at 0x58DE: calloc (in /usr/local/Cellar/valgrind/3.8.1/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==90966== by 0x4E78FA: _xpc_calloc (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4E81D4: _xpc_base_create (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4EDFDA: xpc_dictionary_create (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4EFE63: _libxpc_initializer (in /usr/lib/system/libxpc.dylib)
==90966== by 0x1CFE7D: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==90966== by 0x7FFF5FC0FDA5: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0FAF1: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0D2E3: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0D27C: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0E0B6: ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC034B7: dyld::initializeMainExecutable() (in /usr/lib/dyld)
==90966==
==90966== 616 bytes in 7 blocks are still reachable in loss record 8 of 9
==90966== at 0x58DE: calloc (in /usr/local/Cellar/valgrind/3.8.1/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==90966== by 0x4E78FA: _xpc_calloc (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4E81D4: _xpc_base_create (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4EEBEA: xpc_string_create (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4EDDFD: xpc_dictionary_set_string (in /usr/lib/system/libxpc.dylib)
==90966== by 0x4EFE8C: _libxpc_initializer (in /usr/lib/system/libxpc.dylib)
==90966== by 0x1CFE7D: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==90966== by 0x7FFF5FC0FDA5: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0FAF1: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0D2E3: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0D27C: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966== by 0x7FFF5FC0E0B6: ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==90966==
==90966== 4,096 bytes in 1 blocks are still reachable in loss record 9 of 9
==90966== at 0x5237: malloc (in /usr/local/Cellar/valgrind/3.8.1/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==90966== by 0x34F3F7: __smakebuf (in /usr/lib/system/libsystem_c.dylib)
==90966== by 0x345D19: __swsetup (in /usr/lib/system/libsystem_c.dylib)
==90966== by 0x3466C3: __vfprintf (in /usr/lib/system/libsystem_c.dylib)
==90966== by 0x34618D: vfprintf_l (in /usr/lib/system/libsystem_c.dylib)
==90966== by 0x34F2CF: printf (in /usr/lib/system/libsystem_c.dylib)
==90966== by 0x1000014D0: main (in .//diskimageaccess)
==90966==
==90966== LEAK SUMMARY:
==90966== definitely lost: 0 bytes in 0 blocks
==90966== indirectly lost: 0 bytes in 0 blocks
==90966== possibly lost: 0 bytes in 0 blocks
==90966== still reachable: 6,383 bytes in 33 blocks
==90966== suppressed: 0 bytes in 0 blocks
==90966==
==90966== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==90966== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
编辑:
我尝试将代码转移到 Linux 机器上,它可以完美地编译和运行,没有任何内存错误。有什么想法吗?
最佳答案
如果 valgrind 告诉你的话,那么一定有人正在使用这些函数。如果您确定没有使用任何堆函数,那么您的某些依赖项正在使用 malloc/calloc
。您使用哪些库?
关于C valgrind 仍然可达内存泄漏但没有使用堆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12875381/
有点迷茫.. 在git community manual , 它说 The git log command can show lists of commits. On its own, it show
我是一名优秀的程序员,十分优秀!