我一直在使用以下程序尝试Valgrind:
#include <cstdlib>
#define BUF_SIZE 1000
int main() {
char *path = new char[BUF_SIZE]
return 0;
}
很明显,程序存在内存泄漏,但是当我测试Valgrind时,除了实际的泄漏之外,我还遇到了许多无关的泄漏错误。
我按照https://www.gungorbudak.com/blog/2018/04/28/how-to-install-valgrind-on-macos-high-sierra/
中的说明安装了Valgrind我什至尝试在darwin * .supp中使用--suppressions(来自Git存储库https://sourceware.org/git/?p=valgrind.git)
任何建议都将受到欢迎。
ARIAS-CSC-MBP:cpp arias$ valgrind --leak-check=yes ./test
==72896== Memcheck, a memory error detector
==72896== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==72896== Using Valgrind-3.14.0.GIT and LibVEX; rerun with -h for copyright info
==72896== Command: ./test
==72896==
==72896==
==72896== HEAP SUMMARY:
==72896== in use at exit: 19,411 bytes in 167 blocks
==72896== total heap usage: 188 allocs, 21 frees, 27,859 bytes allocated
==72896==
==72896== 64 bytes in 1 blocks are definitely lost in loss record 27 of 47
==72896== at 0x1000ACC32: calloc (in /usr/local/Cellar/valgrind/HEAD-5f900ed/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==72896== by 0x10075ABA4: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==72896== by 0x10075AC5A: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==72896== by 0x100759363: _read_images (in /usr/lib/libobjc.A.dylib)
==72896== by 0x100757AC4: map_images_nolock (in /usr/lib/libobjc.A.dylib)
==72896== by 0x10076A7DA: objc_object::sidetable_retainCount() (in /usr/lib/libobjc.A.dylib)
==72896== by 0x100007C64: dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) (in /usr/lib/dyld)
==72896== by 0x100007E39: dyld::registerObjCNotifiers(void (*)(unsigned int, char const* const*, mach_header const* const*), void (*)(char const*, mach_header const*), void (*)(char const*, mach_header const*)) (in /usr/lib/dyld)
==72896== by 0x10022271D: _dyld_objc_notify_register (in /usr/lib/system/libdyld.dylib)
==72896== by 0x100757075: _objc_init (in /usr/lib/libobjc.A.dylib)
==72896== by 0x1001ACB34: _os_object_init (in /usr/lib/system/libdispatch.dylib)
==72896== by 0x1001ACB1B: libdispatch_init (in /usr/lib/system/libdispatch.dylib)
==72896==
==72896== 64 bytes in 1 blocks are definitely lost in loss record 28 of 47
==72896== at 0x1000ACC32: calloc (in /usr/local/Cellar/valgrind/HEAD-5f900ed/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==72896== by 0x10075ABA4: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==72896== by 0x10075AC72: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==72896== by 0x10075AC5A: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==72896== by 0x100759363: _read_images (in /usr/lib/libobjc.A.dylib)
==72896== by 0x100757AC4: map_images_nolock (in /usr/lib/libobjc.A.dylib)
==72896== by 0x10076A7DA: objc_object::sidetable_retainCount() (in /usr/lib/libobjc.A.dylib)
==72896== by 0x100007C64: dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) (in /usr/lib/dyld)
==72896== by 0x100007E39: dyld::registerObjCNotifiers(void (*)(unsigned int, char const* const*, mach_header const* const*), void (*)(char const*, mach_header const*), void (*)(char const*, mach_header const*)) (in /usr/lib/dyld)
==72896== by 0x10022271D: _dyld_objc_notify_register (in /usr/lib/system/libdyld.dylib)
==72896== by 0x100757075: _objc_init (in /usr/lib/libobjc.A.dylib)
==72896== by 0x1001ACB34: _os_object_init (in /usr/lib/system/libdispatch.dylib)
==72896==
==72896== 72 bytes in 3 blocks are possibly lost in loss record 29 of 47
==72896== at 0x1000ACC32: calloc (in /usr/local/Cellar/valgrind/HEAD-5f900ed/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==72896== by 0x1007577E2: map_images_nolock (in /usr/lib/libobjc.A.dylib)
==72896== by 0x10076A7DA: objc_object::sidetable_retainCount() (in /usr/lib/libobjc.A.dylib)
==72896== by 0x100007C64: dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) (in /usr/lib/dyld)
==72896== by 0x100007E39: dyld::registerObjCNotifiers(void (*)(unsigned int, char const* const*, mach_header const* const*), void (*)(char const*, mach_header const*), void (*)(char const*, mach_header const*)) (in /usr/lib/dyld)
==72896== by 0x10022271D: _dyld_objc_notify_register (in /usr/lib/system/libdyld.dylib)
==72896== by 0x100757075: _objc_init (in /usr/lib/libobjc.A.dylib)
==72896== by 0x1001ACB34: _os_object_init (in /usr/lib/system/libdispatch.dylib)
==72896== by 0x1001ACB1B: libdispatch_init (in /usr/lib/system/libdispatch.dylib)
==72896== by 0x1000BB9C2: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==72896== by 0x100019AC5: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==72896== by 0x100019CF5: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==72896==
==72896== 1,000 bytes in 1 blocks are definitely lost in loss record 39 of 47
==72896== at 0x1000ACC32: calloc (in /usr/local/Cellar/valgrind/HEAD-5f900ed/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==72896== by 0x100000EF1: main (anothertest.cpp:8)
==72896==
==72896== 1,792 bytes in 28 blocks are definitely lost in loss record 44 of 47
==72896== at 0x1000ACC32: calloc (in /usr/local/Cellar/valgrind/HEAD-5f900ed/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==72896== by 0x10075ABA4: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==72896== by 0x10075AC72: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==72896== by 0x100759363: _read_images (in /usr/lib/libobjc.A.dylib)
==72896== by 0x100757AC4: map_images_nolock (in /usr/lib/libobjc.A.dylib)
==72896== by 0x10076A7DA: objc_object::sidetable_retainCount() (in /usr/lib/libobjc.A.dylib)
==72896== by 0x100007C64: dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) (in /usr/lib/dyld)
==72896== by 0x100007E39: dyld::registerObjCNotifiers(void (*)(unsigned int, char const* const*, mach_header const* const*), void (*)(char const*, mach_header const*), void (*)(char const*, mach_header const*)) (in /usr/lib/dyld)
==72896== by 0x10022271D: _dyld_objc_notify_register (in /usr/lib/system/libdyld.dylib)
==72896== by 0x100757075: _objc_init (in /usr/lib/libobjc.A.dylib)
==72896== by 0x1001ACB34: _os_object_init (in /usr/lib/system/libdispatch.dylib)
==72896== by 0x1001ACB1B: libdispatch_init (in /usr/lib/system/libdispatch.dylib)
==72896==
==72896== LEAK SUMMARY:
==72896== definitely lost: 2,920 bytes in 31 blocks
==72896== indirectly lost: 0 bytes in 0 blocks
==72896== possibly lost: 72 bytes in 3 blocks
==72896== still reachable: 200 bytes in 6 blocks
==72896== suppressed: 16,219 bytes in 127 blocks
==72896== Reachable blocks (those to which a pointer was found) are not shown.
==72896== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==72896==
==72896== For counts of detected and suppressed errors, rerun with: -v
==72896== ERROR SUMMARY: 5 errors from 5 contexts (suppressed: 16 from 16)
答案 0 :(得分:0)
Valgrind当前是macOS High Sierra的预发布软件。由于Valgrind需要以较低的级别挂接到macOS内核(马赫),因此需要不断调整每个主要的新版macOS。
目前,这意味着即使使用Valgrind的开发Git版本,在小型测试可执行文件的进程空间中运行的库代码中也会存在假阳性错误(或至少您无能为力的内存错误)。
Valgrind的未来开发版本可能会解决这些系统错误。如果您未在自己的代码中报告问题,则可以轻松地忽略它们。