Memory Leak
Overview
Memory leaks cause gradual memory consumption growth until the process exhausts available memory (OOM). In long-running servers, even small leaks cause eventual crashes or degraded performance.
Common patterns:
malloc()without correspondingfree()newwithoutdeletein C++- Missing
free()in error exit paths - Goroutine leaks in Go
Remediation
- Use RAII (C++) or smart pointers to manage memory automatically
- Use ASan/Valgrind to detect leaks
- Go: Use context cancellation to stop goroutines
- Ensure all code paths
free()allocated resources