Created
October 19, 2016 07:25
-
-
Save quininer/732db7f577b63f69ea69cc118ffcb98e to your computer and use it in GitHub Desktop.
Rust handle oom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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