I tried to install Valgrind with brew install Valgrind and got :
valgrind: This formula either does not compile or function as expected
on macOS
You can follow alex.m's answer to get valgrind, but if you'r using it on a int main() { return 0; } program, you'll get many weird errors, and non-existing allocs / free.
To 'hide' these annoying errors, you can follow theses steps (it's more a workaround than a real fix) (based on this wiki page and some research in Valgrind's source code):
int main() { return 0; } program.valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-supressions=all --log-file=$YOUR_LOG$ $YOUR_BINARY$
.supp valgrind file: cat ./$YOUR_LOG$ | ./$YOUR_SCRIPT_FILE$ > minimal.supp
minimal.supp content at the end of $YOUR_VALGRIND_INSTALLATION_PATH$/lib/valgrind/default.supp fileAnd you are done! Weird and nonexistent errors will be ignored.
If you also want's to remove the non-existing allocs, frees etc, you can directly edit Valgrind's source code. Or just use heapusage for leak-tracking