Leak Hunter — C memory leaks in VS CodeFinds every block that is allocated and never freed, and shows the file, function and line where it was allocated, with the full call path. Works with any C project (Makefile, CMake, Meson or a plain folder of
Install
Requirements per OS
On Windows you can open the folder in WSL (Remote - WSL): the extension then runs inside Linux and uses Valgrind. With MinGW, build with Two ways to look
Where results appear
Usage
The program runs from its project folder (the one with the
Automatic build (
|
| The project has | Command |
|---|---|
CMakeLists.txt |
cmake --build build --config Debug (configured first if build/ does not exist) |
meson.build |
meson compile -C build (or meson setup build first) |
Makefile |
make (mingw32-make on Windows when make is missing) |
| none of these | no build |
Static analysis and compile_commands.json
If the project has a compile_commands.json (CMake with -DCMAKE_EXPORT_COMPILE_COMMANDS=ON, Meson, or bear -- make), each file is analyzed with its real -I, -D and -std options. Otherwise the header folders of the same project are added with -I.
Settings
| Setting | Default | Purpose |
|---|---|---|
leakHunter.buildCommand |
auto |
auto, empty (no build) or a command. |
leakHunter.tool |
auto |
leaks, valgrind, drmemory or auto (depends on the OS). |
leakHunter.drmemoryPath |
empty | Path to drmemory.exe if it is not found automatically. |
leakHunter.timeoutSeconds |
30 |
Stops the program after this long. |
leakHunter.ignoreFunctions |
[] |
Hides leaks whose stack contains these functions (e.g. readline, rl_*). |
leakHunter.showStillReachable |
false |
Valgrind and Dr. Memory: also show "still reachable" blocks. |
leakHunter.staticAnalysis.analyzer |
auto |
clang, gcc (13+) or auto (clang if installed). |
leakHunter.staticAnalysis.useCompileCommands |
true |
Use compile_commands.json. |
leakHunter.staticAnalysis.exclude |
**/build/**, **/third_party/**, **/vendor/**, **/external/** |
Paths that are not analyzed. |
leakHunter.staticAnalysis.extraFlags |
[] |
Extra clang options (e.g. -DDEBUG=1). |
Command line
node out/cli.js ./my_program arg1 arg2
node out/cli.js ./my_program "<" input.txt
node out/cli.js --static .
How results are computed, and their limits
- macOS:
leaks --atExit -list. Every lost block has its own call stack; blocks allocated at the same line are grouped, with the number of distinct call paths.leaksonly reports when the program goes throughexit(): a crash, a signal or_exitgives no report. A block whose address is still in a register or on the stack at exit is not reported. - Linux:
valgrind --leak-check=full. In "32 (16 direct, 16 indirect) bytes", only the 16 direct bytes are counted on that line, since the indirect ones have their own entry. If the program is killed by a signal, the blocks still held at that point are listed and the signal is named. Valgrind runs without debuginfod downloads (Fedora enables them by default), so it does not wait on the network. - Windows:
drmemory -batch -no_follow_children. Dr. Memory gives a stack only for directly leaked blocks; the blocks only reachable through them are shown as "+ N bytes only reachable through it". Other memory errors it finds (invalid accesses…) are counted in a note. - Child processes: only the main process is analyzed. On macOS, children created with
forkwould stay suspended byleaksat exit (and the parent would wait forever), so they are resumed automatically. - Static analysis: clang may report paths that cannot happen in practice ("Potential leak").
Development
npm install
npm test # unit tests + real runs with this OS's tools (others are skipped)
npm run test:vscode # integration tests in an isolated VS Code instance
npm run preview # dashboard preview at http://127.0.0.1:5173/dev/preview.html
npm run package # builds the .vsix
F5 opens a development window on sample/, a small program that leaks on purpose.
.github/workflows/ci.yml runs the tests on macOS, Ubuntu, Fedora (with and without clang) and Windows (Dr. Memory, MinGW, LLVM).
Publishing a version
Update
versioninpackage.jsonand add a section toCHANGELOG.md.Commit, then push a tag with the same version:
git tag v0.1.1 && git push origin main v0.1.1.github/workflows/release.ymlthen tests, builds the.vsix, attaches it to a GitHub release, and publishes it:- to the VS Code Marketplace if the repository has a
VSCE_PATsecret (a token with the "Marketplace › Manage" scope); - to Open VSX if it has an
OVSX_PATsecret.
Without those secrets the release is still created with the
.vsix, and the publishing steps are skipped.- to the VS Code Marketplace if the repository has a

