TL;DR
MEMHINT is a novel neuro-symbolic pipeline that combines the semantic intuition of Large Language Models (LLMs) with the mathematical rigor of the Z3 SMT solver to detect memory leaks in C/C++ programs. By automatically identifying project-specific custom memory-management functions and filtering out logically impossible execution paths, it discovered 54 unique bugs across major open-source projects with exceptional precision.
What Problem Does This Paper Address?
Memory leaks are a persistent thorn in the side of C/C++ developers, leading to resource depletion, system crashes, and security vulnerabilities. While static application security testing (SAST) tools like CodeQL and Infer scale well to large codebases, they suffer from two fundamental limitations:
- Custom Memory Management Blindness: Large real-world projects rarely rely solely on standard primitives like
mallocandfree. Instead, they wrap them in custom, project-specific functions (e.g.,tree_initorpolicy_tree_freein OpenSSL). Traditional static analyzers do not recognize these custom wrappers, causing them to miss a massive number of leaks. - Path Insensitivity: Static analyzers often merge control-flow branches into abstract paths, leading them to flag leaks on execution paths that are syntactically present but logically impossible at runtime (infeasible paths). This floods developers with frustrating false positives.
Methods
MEMHINT addresses these gaps by framing memory leak detection as a multi-stage neuro-symbolic task, split into three main phases:
- Stage 1: Summary Generation (Neuro + Symbolic Validation): MEMHINT uses Tree-sitter to parse the codebase. A lightweight LLM (Gemini 3 Flash) analyzes the context and classifies custom functions as allocators, deallocators, or neither. Because LLMs can hallucinate, a Z3 SMT solver steps in to validate these summaries against the function's intraprocedural control-flow graph (CFG), ensuring the claimed memory operation is structurally reachable on a feasible path.
- Stage 2: Summary-Augmented Analysis: The validated custom function definitions are automatically translated and injected into CodeQL and Infer via their native extension mechanisms, instantly updating their internal memory models.
- Stage 3: Warning Validation: When the static analyzers generate leak reports, MEMHINT uses Z3 to perform path-feasibility filtering, discarding warnings on logically impossible paths. Finally, a stronger LLM (Gemini 3.1 Pro) reviews the remaining warnings to filter out high-level false positives caused by complex project conventions (like callback-based deallocations or borrowed pointers).
Datasets
The authors evaluated MEMHINT using two distinct datasets:
- Real-World Codebases: Eight widely deployed open-source C/C++ projects totaling over 3.6 million lines of code: Vim, tmux, OpenSSL, Redis, FreeRDP, curl, FFmpeg, and the linux/drivers/staging kernel subsystem.
- Human-Labeled Benchmark: A newly constructed dataset of 1,532 functions sampled across the target projects, independently labeled by two experts to evaluate the precision and recall of custom memory-management function identification.
Key Insights and Ideas
- The Power of Neuro-Symbolic Synergy: LLMs excel at understanding developer intent from naming conventions and code comments (the "human" side of code), while SMT solvers excel at strict mathematical logic. Combining them allows the symbolic layer to act as a rigorous gatekeeper for the LLM's intuition.
- Lightweight Abstractions Scale Better: Instead of performing heavyweight symbolic execution across the entire program, MEMHINT uses a highly optimized, intraprocedural Z3 encoding that tracks just three boolean states for a pointer:
alloc,freed, andescaped. This keeps the constraint solving incredibly fast. - Amortized LLM Costs: Generating function summaries is a one-time upfront cost. Once these custom memory models are generated and validated, they can be reused across future code versions and multiple analyzers without re-running the LLM, making the pipeline highly practical for continuous integration (CI) workflows.
Key Results
- Bug Finding Power: MEMHINT detected 54 unique memory leaks across the eight projects, 53 of which have already been confirmed or fixed by upstream maintainers.
- Baseline Comparison: It vastly outperformed vanilla commercial and academic tools. Vanilla CodeQL found 19 bugs, vanilla Infer found 3, Semgrep found 2, and the state-of-the-art academic tool LeakGuard found 20.
- Flawless Summary Quality: On the human-labeled dataset, MEMHINT achieved 100% precision and recall in identifying reachable custom memory functions, drastically outperforming LeakGuard (34.0% precision, 52.2% recall).
- Cost and Efficiency: The entire pipeline achieved a 2.8–3.1× speedup in the static analysis phase compared to LeakGuard, costing a modest $1.70 per detected bug in LLM API fees.
Limitations and Future Work
- Acyclic CFG Simplification: MEMHINT’s symbolic layer currently treats control flow as acyclic and does not explicitly model loop constructs, meaning it can miss loop-carried memory leaks.
- Scope Restrictions: The tool is strictly focused on memory leaks in C/C++. It does not yet address other critical memory bugs like double-free or use-after-free, nor does it handle other resource leaks like file descriptors or mutex locks.
- Future Directions: The authors plan to introduce bounded loop unrolling to handle loops, expand the summary abstraction to cover other resource types, and explore using LLMs to automatically generate patches (automated program repair) for the leaks discovered by MEMHINT.
Summary updated