about summary refs log tree commit diff
path: root/src/tools/miri/tests/fail/tls_macro_leak.rs
blob: b8a4b81911acad34840bca842772eaf3d3718541 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//@normalize-stderr-test: ".*│.*" -> "$$stripped$$"

use std::cell::Cell;

pub fn main() {
    thread_local! {
        static TLS: Cell<Option<&'static i32>> = Cell::new(None);
    }

    std::thread::spawn(|| {
        TLS.with(|cell| {
            cell.set(Some(Box::leak(Box::new(123)))); //~ERROR: memory leaked
        });
    })
    .join()
    .unwrap();

    // Imagine the program running for a long time while the thread is gone
    // and this memory still sits around, unused -- leaked.
}