jonhoo / guardian

Owned mutex guards for refcounted mutexes.
Apache License 2.0
14 stars 4 forks source link

Ensure inner lock drop before handle #2

Closed treere closed 2 years ago

treere commented 2 years ago

Hi!

When one of the guardian struct is the only one keeping the handler alive, during drop the stack/heap is corrupted.

pub struct Example {
    _handle: Arc<Mutex<i8>>,
    inner: MutexGuard<'static, i8>,
}

If _handle is dropped before inner, when inner is dropped it tries to unlock _handler but it has already been dropped.

The drop field order in Rust is not fixed so I used an Option to force the right order.

Have a nice day!

treere commented 2 years ago

Thanks for the review! I have applied the changes

jonhoo commented 2 years ago

Published as 1.0.2!