How std::mem::forget Silently Leaks Heap Memory and Triggers Linux OOM Kills
Rust's std::mem::forget function drops a stack-allocated handle without executing destructor logic, permanently orphaning the associated heap metadata inside allocator arenas. Because the operation produces no undefined behavior, tools like memory sanitizers raise no alerts and the Linux kernel logs no faults at the time of the call. Over weeks of sustained production throughput, the leaked allocations cause the process's Resident Set Size to grow monotonically, fragmenting virtual memory without generating panics or heap corruption reports. Eventually, the Linux kernel's Out-Of-Memory killer issues an uncatchable SIGKILL to the process, leaving engineers with no crash dump to diagnose. The root cause lies in how ManuallyDrop suppresses Rust's drop elaboration pass, preventing the compiler from emitting any call to the allocator's deallocation hook.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in