2022-06-20 18:00:37 -05:00
|
|
|
use std::{
|
|
|
|
ptr,
|
|
|
|
sync::atomic::{AtomicPtr, Ordering},
|
|
|
|
};
|
2020-12-09 17:09:52 -06:00
|
|
|
|
2020-04-04 06:35:30 -05:00
|
|
|
static mut LEAKER: Option<Box<Vec<i32>>> = None;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// Having memory "leaked" in globals is allowed.
|
|
|
|
unsafe {
|
|
|
|
LEAKER = Some(Box::new(vec![0; 42]));
|
|
|
|
}
|
2020-12-09 17:09:52 -06:00
|
|
|
|
|
|
|
// Make sure this is allowed even when `AtomicPtr` is used.
|
|
|
|
{
|
|
|
|
static LEAK: AtomicPtr<usize> = AtomicPtr::new(ptr::null_mut());
|
|
|
|
LEAK.store(Box::into_raw(Box::new(0usize)), Ordering::SeqCst);
|
2020-12-21 04:33:46 -06:00
|
|
|
|
|
|
|
static LEAK2: AtomicPtr<usize> = AtomicPtr::new(ptr::null_mut());
|
|
|
|
// Make sure this also works when using 'swap'.
|
|
|
|
LEAK2.swap(Box::into_raw(Box::new(0usize)), Ordering::SeqCst);
|
2020-12-09 17:09:52 -06:00
|
|
|
}
|
2020-04-04 06:35:30 -05:00
|
|
|
}
|