typescript.unbounded_memory
Stability
High
Detects data structures that can grow without bounds, leading to OOM.
Why It Matters
Section titled “Why It Matters”Unbounded memory:
- Causes OOM — Process crashes
- Cascading failures — Other services impacted
- Hard to diagnose — Gradual memory growth
Example
Section titled “Example”// ❌ Before (unbounded array)const events: Event[] = [];
socket.on('event', (event) => { events.push(event); // Grows forever!});// ✅ After (with limit)import { CircularBuffer } from 'circular-buffer';
const events = new CircularBuffer<Event>(1000);
socket.on('event', (event) => { events.push(event); // Old events evicted});
// Or with manual limit:const MAX_EVENTS = 1000;const events: Event[] = [];
socket.on('event', (event) => { if (events.length >= MAX_EVENTS) { events.shift(); } events.push(event);});What Unfault Detects
Section titled “What Unfault Detects”- Arrays growing in event handlers
- Maps/Sets accepting unbounded input
- Queues without size limits
Auto-Fix
Section titled “Auto-Fix”Unfault adds capacity limits and bounds checks.