Skip to content
| Marketplace
Sign in
Visual Studio Code>Linters>C Memory PoliceNew to Visual Studio Code? Get it now.
C Memory Police

C Memory Police

fitz353

|
3 installs
| (0) | Free
Detects potential memory leaks in C code by matching malloc/calloc with free within each function
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

C Memory Police

A VS Code extension that detects potential memory leaks in C code by checking each function for unmatched malloc/calloc allocations.

Features

  • Function-level analysis: Checks every function body for malloc/calloc calls that are never free()d
  • Modular project support: Follows #include "..." directives into custom headers and their .c files to detect allocating functions
  • Real-time feedback: Analyzes while you type (500ms debounce) and on save
  • Warning diagnostics: Shows yellow squiggly underlines + entries in the Problems panel
  • Helpful hover messages: Hover over a warning to see which variable leaked and how to fix it
  • Comment-aware: Ignores malloc/calloc calls inside comments

How it Works

  1. When you open or edit a .c file, the extension scans for #include "..." directives
  2. It parses my custom header's corresponding .c file to find functions that call malloc/calloc internally
  3. It parses every function in your file and checks:
    • Is there a malloc() or calloc() call?
    • Is the result variable passed to free() before the function ends?
    • Is there a call to a known allocating function whose result is never freed?
  4. If a leak is found, a yellow warning appears on the allocation line

Usage

Just open a .c file — the extension activates automatically!

Or run the command: C Memory Police: Check Current File from the command palette (Ctrl+Shift+P).

Testing

Open test/test_main.c in the Extension Development Host to see the extension in action. Expected warnings:

  • leaked_ptr — malloc without free
  • data — calloc without free
  • buffer — call to create_buffer() (which internally mallocs) without free
  • temp in process_data() — malloc without free
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft