Skip to content

Commit f0d9157

Browse files
committed
Add tests for double destroying various pthread items
1 parent ae12056 commit f0d9157

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// ignore-windows: No libc on Windows
2+
#![feature(rustc_private)]
3+
4+
/// Test that destroying a pthread_cond twice fails, even without a check for number validity
5+
extern crate libc;
6+
7+
fn main() {
8+
unsafe {
9+
use core::mem::MaybeUninit;
10+
let mut attr = MaybeUninit::<libc::pthread_condattr_t>::uninit();
11+
libc::pthread_condattr_init(attr.as_mut_ptr());
12+
13+
let mut cond = MaybeUninit::<libc::pthread_cond_t>::uninit();
14+
15+
libc::pthread_cond_init(cond.as_mut_ptr(), attr.as_ptr());
16+
17+
libc::pthread_cond_destroy(cond.as_mut_ptr());
18+
19+
libc::pthread_cond_destroy(cond.as_mut_ptr());
20+
//~^ Undefined Behavior: using uninitialized data, but this operation requires initialized memory
21+
}
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// ignore-windows: No libc on Windows
2+
#![feature(rustc_private)]
3+
4+
/// Test that destroying a pthread_mutex twice fails, even without a check for number validity
5+
extern crate libc;
6+
7+
fn main() {
8+
unsafe {
9+
use core::mem::MaybeUninit;
10+
11+
let mut attr = MaybeUninit::<libc::pthread_mutexattr_t>::uninit();
12+
libc::pthread_mutexattr_init(attr.as_mut_ptr());
13+
14+
let mut mutex = MaybeUninit::<libc::pthread_mutex_t>::uninit();
15+
16+
libc::pthread_mutex_init(mutex.as_mut_ptr(), attr.as_ptr());
17+
18+
libc::pthread_mutex_destroy(mutex.as_mut_ptr());
19+
20+
libc::pthread_mutex_destroy(mutex.as_mut_ptr());
21+
//~^ Undefined Behavior: using uninitialized data, but this operation requires initialized memory
22+
}
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// ignore-windows: No libc on Windows
2+
#![feature(rustc_private)]
3+
4+
/// Test that destroying a pthread_mutexattr twice fails, even without a check for number validity
5+
extern crate libc;
6+
7+
fn main() {
8+
unsafe {
9+
use core::mem::MaybeUninit;
10+
let mut attr = MaybeUninit::<libc::pthread_mutexattr_t>::uninit();
11+
12+
libc::pthread_mutexattr_init(attr.as_mut_ptr());
13+
14+
libc::pthread_mutexattr_destroy(attr.as_mut_ptr());
15+
16+
libc::pthread_mutexattr_destroy(attr.as_mut_ptr());
17+
//~^ Undefined Behavior: using uninitialized data, but this operation requires initialized memory
18+
}
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// ignore-windows: No libc on Windows
2+
#![feature(rustc_private)]
3+
4+
/// Test that destroying a pthread_rwlock twice fails, even without a check for number validity
5+
extern crate libc;
6+
7+
fn main() {
8+
unsafe {
9+
let mut lock = libc::PTHREAD_RWLOCK_INITIALIZER;
10+
11+
libc::pthread_rwlock_destroy(&mut lock);
12+
13+
libc::pthread_rwlock_destroy(&mut lock);
14+
//~^ Undefined Behavior: using uninitialized data, but this operation requires initialized memory
15+
}
16+
}

0 commit comments

Comments
 (0)