Skip to content

Instantly share code, notes, and snippets.

@SiegeLord
Created April 6, 2014 02:18
Show Gist options
  • Select an option

  • Save SiegeLord/10000695 to your computer and use it in GitHub Desktop.

Select an option

Save SiegeLord/10000695 to your computer and use it in GitHub Desktop.
Double free
use std::cast;
use std::libc::{c_void, malloc, free};
struct A
{
a: *mut c_void
}
impl Drop for A
{
fn drop(&mut self)
{
println!("drop");
unsafe
{
free(self.a);
}
}
}
impl A
{
fn new() -> A
{
unsafe
{
A{ a: malloc(10) }
}
}
fn bloop(self) -> A
{
A{ a: self.a }
}
}
fn main()
{
let a = A::new();
let b = a.bloop();
println!("Here");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment