Software Engineering
New AI-Powered Tool Catches Memory Leaks Standard Code Analyzers Miss
A hybrid approach pairing large language models with symbolic reasoning significantly outperforms conventional static analyzers at finding hidden bugs in C and C++ programs.
Memory leaks—silent but costly bugs where programs fail to free memory—continue to plague large C and C++ codebases despite decades of tooling efforts. Traditional static analyzers like CodeQL can scan millions of lines of code quickly, but they frequently miss these problems because they don't understand custom memory-management functions unique to each project and struggle to reason carefully about control flow.
How MemHint Works#
Researchers have developed MemHint, a system that combines the semantic reasoning power of large language models with the mathematical rigor of symbolic analysis. The pipeline operates in several stages:
- An LLM examines each function in the target codebase and classifies it as a memory allocator (one that reserves memory), deallocator (one that frees it), or neither—then documents which parameter or return value controls memory ownership
- A Z3-based symbolic checker validates each LLM prediction by tracing through the function's control-flow graph, discarding any claims that don't hold on all executable paths
- The validated summaries are fed into CodeQL and Infer (two industry-standard analyzers) through their official extension interfaces
- Z3 filters out alerts triggered by impossible code paths, reducing false positives
- A final LLM step confirms whether each remaining warning represents a genuine bug
Real-World Results#
Tested on eight substantial C/C++ projects spanning over 3.6 million lines of code, MemHint uncovered 54 genuine memory leaks, all of which have been verified or patched. By comparison, vanilla CodeQL found 19 and vanilla Infer found only 3. The cost per detected bug came to approximately $1.70, demonstrating practical efficiency.
Why It Matters#
The hybrid approach addresses a fundamental gap: static tools alone lack project-specific knowledge about memory semantics, while LLMs alone cannot guarantee logical soundness. By combining both—using neural networks for semantic understanding and formal reasoning for verification—the system achieves higher accuracy on a class of bugs that, while well-understood, remains notoriously difficult to eliminate at scale.