Valgrind shows memory leak on empty program on Mac

2020-07-10 08:05发布

问题:

Valgrind installed using brew.

#include <stdio.h>
#include <stdlib.h>
int main()
{
    return 0;
}

gcc -g -o hello hello.c

valgrind --tool=memcheck --leak-check=yes ./hello

回答1:

This is not a memory leak you need to worry about. ImageLoader is part of the OS X runtime and is responsible for loading binaries and dynamic libraries. It allocates some memory once, during initialization and forgets about it, but it's harmless because it's a small block of memory allocated only once. And it does a bunch of things that Valgrind doesn't like but that aren't incorrect. You should add these to your suppression file.



回答2:

Mac OSX 10.8 support in Valgrind is still limited. ImageLoaderMachO::doInitialization... should be in your suppression file.



回答3:

The other answer is correct, I just happened to have the same problem and had a little trouble creating the suppression file. So, to help others, here is the minimal suppression file I generated for Mac OS X Mountain Lion: https://www.dropbox.com/s/2btyqnf8uesgsis/minimal.supp