Skip to content

Instantly share code, notes, and snippets.

@quininer
Created October 19, 2016 07:25
Show Gist options
  • Save quininer/732db7f577b63f69ea69cc118ffcb98e to your computer and use it in GitHub Desktop.
Save quininer/732db7f577b63f69ea69cc118ffcb98e to your computer and use it in GitHub Desktop.
Rust handle oom
extern crate nix;
use nix::sys::signal;
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
println!("drop.");
}
}
extern fn oomhook(_: i32) { panic!("oom!") }
fn main() {
let foo = Foo;
let sigaction = signal::SigAction::new(
signal::SigHandler::Handler(oomhook),
signal::SA_SIGINFO,
signal::SigSet::empty(),
);
unsafe { signal::sigaction(signal::SIGILL, &sigaction).ok() };
vec![0; 999999999999999];
}
[I] ➜ testoom git:(master) ✗ cargo run
Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs
Running `target/debug/testoom`
fatal runtime error: out of memory
thread 'main' panicked at 'oom!', src/main.rs:13
note: Run with `RUST_BACKTRACE=1` for a backtrace.
drop.
error: process didn't exit successfully: `target/debug/testoom` (exit code: 101)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment