rust-embedded / bare-metal

Abstractions common to microcontrollers
Apache License 2.0
116 stars 17 forks source link

Soundness issue in the Mutex API #6

Closed TethysSvensson closed 6 years ago

TethysSvensson commented 6 years ago

This function can be compiled and leaks a reference to the stack:

fn bad(cs: &bare_metal::CriticalSection) -> &u32 {
    let x = bare_metal::Mutex::new(42u32);
    x.borrow(cs)
}

The solution is to change the type signature of borrow to:

pub fn borrow<'cs>(&'cs self, _cs: &'cs CriticalSection) -> &'cs T