Skip to content

rust.unbounded_memory

Stability High

Detects data structures that can grow without bounds, leading to OOM.

Unbounded memory:

  • Causes OOM — Process killed by OS
  • Cascading failures — Other services impacted
  • Hard to diagnose — Gradual memory growth
// ❌ Before (unbounded Vec)
fn collect_items(stream: impl Stream<Item = Item>) -> Vec<Item> {
let mut items = Vec::new();
while let Some(item) = stream.next().await {
items.push(item); // Grows forever!
}
items
}
// ✅ After (with capacity limit)
fn collect_items(stream: impl Stream<Item = Item>, max: usize) -> Vec<Item> {
let mut items = Vec::with_capacity(max.min(1000));
while let Some(item) = stream.next().await {
if items.len() >= max {
break; // Stop at limit
}
items.push(item);
}
items
}
  • Vecs without capacity hints growing in loops
  • HashMaps accepting unbounded input
  • Channels without buffer limits

Unfault adds capacity limits and bounds checks.