Skip to content
| Marketplace
Sign in
Visual Studio Code>Linters>Leak Hunter — C memory leaksNew to Visual Studio Code? Get it now.
Leak Hunter — C memory leaks

Leak Hunter — C memory leaks

Preview

Tortoil

|
2 installs
| (0) | Free
Finds the memory leaks of any C program (leaks on macOS, Valgrind on Linux, Dr. Memory on Windows, clang or GCC static analysis) and shows the file, function and line of each one.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Leak Hunter — C memory leaks in VS Code

Finds 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 .c files, including a folder that holds several projects) on macOS, Linux (Fedora, Ubuntu, Debian, Arch…) and Windows.

Preview. This first version is tested on macOS, Ubuntu, Fedora and Windows Server 2022 (see the CI). Issues and ideas are welcome on GitHub.

Dashboard after running a program: 112 bytes lost, where they were allocated and the call path

Static analysis in the light theme: the path the analyzer followed to the leak

Install

  • VS Code: search for "Leak Hunter" in the Extensions view, or run code --install-extension tortoil.leak-hunter.
  • VSCodium, Cursor and other editors using Open VSX: search for "Leak Hunter" in their extension view.
  • From a file: download the .vsix from the GitHub releases, then code --install-extension leak-hunter-<version>.vsix.

Requirements per OS

OS Run the program Static analysis
macOS leaks (Xcode command line tools: xcode-select --install) clang (same tools)
Fedora Valgrind: sudo dnf install valgrind clang (sudo dnf install clang) or GCC 13+ (Fedora's default)
Ubuntu / Debian Valgrind: sudo apt install valgrind clang (sudo apt install clang) or GCC 13+
Windows 10 / 11 up to 23H2, Server 2022 Dr. Memory (choco install drmemory), or set leakHunter.drmemoryPath clang (LLVM: winget install LLVM.LLVM) or MinGW GCC 13+
Windows 11 24H2, Server 2025 WSL only (see below): Dr. Memory cannot start programs there, even its December 2025 development build same as above

On Windows you can open the folder in WSL (Remote - WSL): the extension then runs inside Linux and uses Valgrind. With MinGW, build with -g -gdwarf-4: Dr. Memory does not read the DWARF 5 debug info that recent GCC writes by default, and shows no line numbers without it. The same goes for Remote - SSH and Dev Containers: the tools must be installed where the code is.

Two ways to look

Run the program (▶) Builds the project, runs the program under leaks (macOS), Valgrind (Linux) or Dr. Memory (Windows) and collects every lost block. Only sees the code paths that actually run.
Static analysis (🔍) Reads the code with clang's analyzer, or GCC's (-fanalyzer, GCC 13+) when clang is not installed, without running anything. Files are analyzed one by one, so a leak that spans several files can be missed.

Where results appear

  • Dashboard: total bytes lost, a chart per function, one card per allocation site with the code snippet and a clickable call path.
  • Editor: a drop in the gutter, ◀ leak: 96 bytes at the end of the line, a squiggle listed in the Problems panel.
  • Side view: files › functions › leaks.
  • Status bar: bytes lost, or No leaks.

Usage

  1. Open the project folder.
  2. Click ▶ at the top of a .c file, or the Leak Hunter icon in the activity bar.
  3. Pick the executable, then its arguments. Quotes are supported and < file feeds a file to standard input. The choice is remembered; click the target in the dashboard to change it.

The program runs from its project folder (the one with the Makefile, CMakeLists.txt or meson.build), with an empty standard input unless redirected. On Windows, pick the .exe.

Build with debug info for exact line numbers: -g (gcc, clang), -g -gdwarf-4 (MinGW with Dr. Memory) or /Zi (MSVC). Without it, the file and function are still found from the binary's symbols.

Automatic build (leakHunter.buildCommand = auto)

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. leaks only reports when the program goes through exit(): a crash, a signal or _exit gives 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 fork would stay suspended by leaks at 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

  1. Update version in package.json and add a section to CHANGELOG.md.

  2. Commit, then push a tag with the same version:

    git tag v0.1.1 && git push origin main v0.1.1
    
  3. .github/workflows/release.yml then tests, builds the .vsix, attaches it to a GitHub release, and publishes it:

    • to the VS Code Marketplace if the repository has a VSCE_PAT secret (a token with the "Marketplace › Manage" scope);
    • to Open VSX if it has an OVSX_PAT secret.

    Without those secrets the release is still created with the .vsix, and the publishing steps are skipped.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft