Compiling Valgrind on Snow Leopard

Checkout the valgrind sources:

svn co svn://svn.valgrind.org/valgrind/tags/VALGRIND_3_5_0 valgrind


Download Greg Parker's 10.6 patch
curl http://bugsfiles.kde.org/attachment.cgi?id=36999 > 10.6.patch
mv 10.6.patch ./valgrind


Apply the patch

cd valgrind
patch -p0 < 10.6.patch


Compile valgrind (if you want to run it on 64 bit binaries, use "./configure --build=amd64-darwin", otherwise you'll build it for 32 bits)
./autogen.sh
./configure
make


Install it
sudo make install


Run it
cristi:tmp diciu$ cat /tmp/test.c
int main()
{
char * t = malloc(1024);
char * w = "Ana";

t = w;
}
cristi:tmp diciu$ gcc -arch i386 /tmp/test.c
cristi:tmp diciu$ valgrind --leak-check=full /tmp/a.out
[..]
==938== HEAP SUMMARY:
==938== in use at exit: 1,344 bytes in 8 blocks
==938== total heap usage: 8 allocs, 0 frees, 1,344 bytes allocated
==938==
==938== 1,024 bytes in 1 blocks are definitely lost in loss record 4 of 4
==938== at 0xF666: malloc (vg_replace_malloc.c:195)
==938== by 0x1F66: main (in /tmp/a.out)