Skip to content

Commit b4fe8f3

Browse files
committed
Leak pthreax_rwlock_t when it's dropped while locked.
1 parent d722944 commit b4fe8f3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

library/std/src/sys/unix/locks/pthread_rwlock.rs

+15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ impl LazyInit for RwLock {
1717
fn init() -> Box<Self> {
1818
Box::new(Self::new())
1919
}
20+
21+
fn destroy(mut rwlock: Box<Self>) {
22+
// We're not allowed to pthread_rwlock_destroy a locked rwlock,
23+
// so check first if it's unlocked.
24+
if *rwlock.write_locked.get_mut() || *rwlock.num_readers.get_mut() != 0 {
25+
// The rwlock is locked. This happens if a RwLock{Read,Write}Guard is leaked.
26+
// In this case, we just leak the RwLock too.
27+
forget(rwlock);
28+
}
29+
}
30+
31+
fn cancel_init(_: Box<Self>) {
32+
// In this case, we can just drop it without any checks,
33+
// since it cannot have been locked yet.
34+
}
2035
}
2136

2237
impl RwLock {

0 commit comments

Comments
 (0)