I am running a simple application in C using gcc compiler, and testing it with valgrind. I installed valgrind from homebrew (version: valgrind-3.13.0) and I keep getting a memory leak error, even when running a simple program. I get ERROR SUMMARY: 7 errors from 7 contexts (suppressed: 13 from 13) all problems seem to come from /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)
The program it is running is the following, compiled with gcc -c -std=c99:
#include <stdio.h>
int main (void){
printf("Hello World\n");
return 0;
}
This is Valgrind Bug 379373. It was already fixed. To get this fix you can try to build Valgrind yourself from source code. See Source Code Repository for instructions.