Skip to content

[BUG] Memory leak detected in Tiny Shell process management #4

@sumin-world

Description

@sumin-world

Bug Description

When running Tiny Shell under moderate load (spawning/exiting many child processes), memory usage grows over time and is not reclaimed. After ~1000 short-lived commands, the process RSS steadily increases until OOM occurs on constrained containers.

To Reproduce

Steps to reproduce the behavior:

  1. Build and run Tiny Shell:
git checkout <commit-hash>
cargo build --release
  1. Run a loop to spawn multiple short-lived processes:
for i in $(seq 1 2000); do ./target/release/tinysh -c "true"; done
  1. Monitor memory usage:
# In a separate terminal
watch -n 1 'ps aux | grep tinysh | head -n 1'

Expected Behavior

Memory footprint should remain stable with resources being properly freed after each child process exits.

Actual Behavior

  • Resident memory (RSS) steadily increases and is not freed
  • Observed ~10–20MB leak per 100–200 commands (platform dependent)
  • Eventually leads to OOM in memory-constrained containers

Environment

  • OS: Ubuntu 22.04 / macOS 12
  • Rust Version: stable (1.70.0 – please specify exact version)
  • Build Command: cargo build --release
  • Commit:
  • Module: tiny-shell

Additional Context / Investigation Clues

  • No panic or crash observed during execution
  • valgrind / jemalloc profiling suggests missing cleanup in process table or wait handling
  • Suspected issue in child reaping path (wait() / waitpid() calls)
  • Memory appears to accumulate with each process spawn/exit cycle

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsecurity

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions