valgrind
brew install valgrind
valgrind --leak-check=yes myprog arg1 arg2
valgrind --leak-check=full --show-leak-kinds=all --verbose --track-origins=yes myprog
int run_within_valgrind (void) {
char *p = getenv ("LD_PRELOAD");
if (p == NULL)
return 0;
return (strstr (p, "/valgrind/") != NULL || strstr (p, "/vgpreload") != NULL);
}