我正在使用gcc编译器在C中运行一个简单的应用程序,并使用valgrind对其进行测试。我从自制软件安装valgrind(版本:valgrind-3.13.0),即使运行一个简单的程序,我仍然会收到内存泄漏错误。我得到错误摘要:来自7个上下文的7个错误(被抑制:13个中的13个)所有问题似乎来自/ usr / lib / dyld。
==2041== Memcheck, a memory error detector
==2041== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2041== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==2041== Command: ./simple
==2041==
==2041== Syscall param msg->desc.port.name points to uninitialised byte(s)
==2041== at 0x1003A834A: mach_msg_trap (in /usr/lib/system/libsystem_kernel.dylib)
==2041== by 0x1003A7796: mach_msg (in /usr/lib/system/libsystem_kernel.dylib)
==2041== by 0x1003A1485: task_set_special_port (in /usr/lib/system/libsystem_kernel.dylib)
==2041== by 0x10053D10E: _os_trace_create_debug_control_port (in /usr/lib/system/libsystem_trace.dylib)
==2041== by 0x10053D458: _libtrace_init (in /usr/lib/system/libsystem_trace.dylib)
==2041== by 0x1000A69DF: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==2041== by 0x100018A1A: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==2041== by 0x100018C1D: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==2041== by 0x1000144A9: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in /usr/lib/dyld)
==2041== by 0x100014440: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in /usr/lib/dyld)
==2041== by 0x100013523: ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in /usr/lib/dyld)
==2041== by 0x1000135B8: ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==2041== Address 0x10488be2c is on thread 1's stack
==2041== in frame #2, created by task_set_special_port (???:)
==2041==
Hello World
==2041==
==2041== HEAP SUMMARY:
==2041== in use at exit: 22,274 bytes in 163 blocks
==2041== total heap usage: 179 allocs, 16 frees, 28,418 bytes allocated
==2041==
==2041== 64 bytes in 1 blocks are definitely lost in loss record 23 of 43
==2041== at 0x100098C7A: calloc (in /usr/local/Cellar/valgrind/3.13.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==2041== by 0x1005B4BA0: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B4C4D: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B4C4D: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B32D1: _read_images (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B1A29: map_images_nolock (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005C4FE8: objc_object::sidetable_retainCount() (in /usr/lib/libobjc.A.dylib)
==2041== by 0x10000803B: dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) (in /usr/lib/dyld)
==2041== by 0x100008255: 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)
==2041== by 0x1001FF00A: _dyld_objc_notify_register (in /usr/lib/system/libdyld.dylib)
==2041== by 0x1005B1074: _objc_init (in /usr/lib/libobjc.A.dylib)
==2041== by 0x10019268D: _os_object_init (in /usr/lib/system/libdispatch.dylib)
==2041==
==2041== 64 bytes in 1 blocks are definitely lost in loss record 24 of 43
==2041== at 0x100098C7A: calloc (in /usr/local/Cellar/valgrind/3.13.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==2041== by 0x1005B4BA0: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B4C6E: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B4C4D: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B4C4D: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B32D1: _read_images (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B1A29: map_images_nolock (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005C4FE8: objc_object::sidetable_retainCount() (in /usr/lib/libobjc.A.dylib)
==2041== by 0x10000803B: dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) (in /usr/lib/dyld)
==2041== by 0x100008255: 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)
==2041== by 0x1001FF00A: _dyld_objc_notify_register (in /usr/lib/system/libdyld.dylib)
==2041== by 0x1005B1074: _objc_init (in /usr/lib/libobjc.A.dylib)
==2041==
==2041== 72 bytes in 3 blocks are possibly lost in loss record 25 of 43
==2041== at 0x100098C7A: calloc (in /usr/local/Cellar/valgrind/3.13.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==2041== by 0x1005B1846: map_images_nolock (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005C4FE8: objc_object::sidetable_retainCount() (in /usr/lib/libobjc.A.dylib)
==2041== by 0x10000803B: dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) (in /usr/lib/dyld)
==2041== by 0x100008255: 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)
==2041== by 0x1001FF00A: _dyld_objc_notify_register (in /usr/lib/system/libdyld.dylib)
==2041== by 0x1005B1074: _objc_init (in /usr/lib/libobjc.A.dylib)
==2041== by 0x10019268D: _os_object_init (in /usr/lib/system/libdispatch.dylib)
==2041== by 0x10019263A: libdispatch_init (in /usr/lib/system/libdispatch.dylib)
==2041== by 0x1000A69D5: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==2041== by 0x100018A1A: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==2041== by 0x100018C1D: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==2041==
==2041== 192 bytes in 3 blocks are definitely lost in loss record 29 of 43
==2041== at 0x100098C7A: calloc (in /usr/local/Cellar/valgrind/3.13.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==2041== by 0x1005B4BA0: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B4C4D: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B32D1: _read_images (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B1A29: map_images_nolock (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005C4FE8: objc_object::sidetable_retainCount() (in /usr/lib/libobjc.A.dylib)
==2041== by 0x10000803B: dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) (in /usr/lib/dyld)
==2041== by 0x100008255: 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)
==2041== by 0x1001FF00A: _dyld_objc_notify_register (in /usr/lib/system/libdyld.dylib)
==2041== by 0x1005B1074: _objc_init (in /usr/lib/libobjc.A.dylib)
==2041== by 0x10019268D: _os_object_init (in /usr/lib/system/libdispatch.dylib)
==2041== by 0x10019263A: libdispatch_init (in /usr/lib/system/libdispatch.dylib)
==2041==
==2041== 192 bytes in 3 blocks are definitely lost in loss record 30 of 43
==2041== at 0x100098C7A: calloc (in /usr/local/Cellar/valgrind/3.13.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==2041== by 0x1005B4BA0: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B4C6E: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B4C4D: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B32D1: _read_images (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B1A29: map_images_nolock (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005C4FE8: objc_object::sidetable_retainCount() (in /usr/lib/libobjc.A.dylib)
==2041== by 0x10000803B: dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) (in /usr/lib/dyld)
==2041== by 0x100008255: 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)
==2041== by 0x1001FF00A: _dyld_objc_notify_register (in /usr/lib/system/libdyld.dylib)
==2041== by 0x1005B1074: _objc_init (in /usr/lib/libobjc.A.dylib)
==2041== by 0x10019268D: _os_object_init (in /usr/lib/system/libdispatch.dylib)
==2041==
==2041== 2,944 bytes in 46 blocks are definitely lost in loss record 41 of 43
==2041== at 0x100098C7A: calloc (in /usr/local/Cellar/valgrind/3.13.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==2041== by 0x1005B4BA0: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B4C6E: realizeClass(objc_class*) (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B32D1: _read_images (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005B1A29: map_images_nolock (in /usr/lib/libobjc.A.dylib)
==2041== by 0x1005C4FE8: objc_object::sidetable_retainCount() (in /usr/lib/libobjc.A.dylib)
==2041== by 0x10000803B: dyld::notifyBatchPartial(dyld_image_states, bool, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), bool, bool) (in /usr/lib/dyld)
==2041== by 0x100008255: 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)
==2041== by 0x1001FF00A: _dyld_objc_notify_register (in /usr/lib/system/libdyld.dylib)
==2041== by 0x1005B1074: _objc_init (in /usr/lib/libobjc.A.dylib)
==2041== by 0x10019268D: _os_object_init (in /usr/lib/system/libdispatch.dylib)
==2041== by 0x10019263A: libdispatch_init (in /usr/lib/system/libdispatch.dylib)
==2041==
==2041== LEAK SUMMARY:
==2041== definitely lost: 3,456 bytes in 54 blocks
==2041== indirectly lost: 0 bytes in 0 blocks
==2041== possibly lost: 72 bytes in 3 blocks
==2041== still reachable: 200 bytes in 6 blocks
==2041== suppressed: 18,546 bytes in 100 blocks
==2041== Reachable blocks (those to which a pointer was found) are not shown.
==2041== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==2041==
==2041== For counts of detected and suppressed errors, rerun with: -v
==2041== Use --track-origins=yes to see where uninitialised values come from
==2041== ERROR SUMMARY: 7 errors from 7 contexts (suppressed: 13 from 13)
它运行的程序如下,用gcc -c -std = c99编译:
#include <stdio.h>
int main (void){
printf("Hello World\n");
return 0;
}
这是Valgrind Bug 379373。它已经修好了。要获得此修复,您可以尝试从源代码自己构建Valgrind。有关说明,请参阅Source Code Repository。