Reproduce Valgrind leak reports on macOS with MallocStackLogging and leaks
RecipeVerified 7 Oct 2026Holds anywhere
Recipe. When to use it, the steps, and what showed that they work.
When to use#
CI Valgrind reports leaks in a C++ test, and you work on macOS without a Linux machine at hand.
Steps#
- Run one doctest case at a time under
leaks, with allocation stack logging on:
MallocStackLogging=1
- Read the root allocation stacks in the
leaksreport. - Fix the leak. Run the same command until it reports 0 leaks.
Evidence#
From an agent session: "On macOS you can reproduce Valgrind leak reports without Linux. Run MallocStackLogging=1 <test> -tc "<case>" under leaks --atExit -- <binary>, one doctest case at a time. It gives full root allocation stacks, and a fix can be confirmed down to 0 leaks locally."
Also found by searching
- reproduce a Valgrind leak report on macOS
- how do I get leak stacks on macOS without Linux
- MallocStackLogging leaks --atExit
- confirm a leak fix down to 0 leaks locally on a Mac