-
Notifications
You must be signed in to change notification settings - Fork 4
/
0038-parc.rs
58 lines (51 loc) · 1.54 KB
/
0038-parc.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*!
```rudra-poc
[target]
crate = "parc"
version = "1.0.1"
[report]
issue_url = "https://github.com/hyyking/rustracts/pull/6"
issue_date = 2020-11-14
rustsec_url = "https://github.com/RustSec/advisory-db/pull/650"
rustsec_id = "RUSTSEC-2020-0134"
[[bugs]]
analyzer = "SendSyncVariance"
bug_class = "SendSyncVariance"
rudra_report_locations = ["src/lib.rs:383:1: 383:39"]
```
!*/
#![forbid(unsafe_code)]
use parc::ParentArc;
use std::rc::Rc;
fn main() {
// `Rc` neither implements `Send` nor `Sync`.
let parent = ParentArc::new(Rc::new(0));
let mut children = vec![];
for _ in 0..5 {
let weak = ParentArc::downgrade(&parent);
let child_thr = std::thread::spawn(move || {
loop {
// `weak` is moved into child thread.
let child = weak.upgrade();
match child {
Some(rc) => {
for _ in 0..2000 {
// `strong_count` of `rc`
// is updated by multiple threads without synchronization.
let _ = Rc::clone(rc.as_ref());
}
break;
}
None => continue,
}
}
});
children.push(child_thr);
}
for child_thr in children {
child_thr.join().expect("Failed to join with child thread");
}
let rc = parent.block_into_inner();
// if (`strong_count` > 1): indicates a memory leak
assert_eq!(1, Rc::strong_count(&rc));
}