@@ -7,46 +7,45 @@ void t3(int i, std::mutex *pm) { delete pm; }
7
7
8
8
void f1 () {
9
9
std::thread threads[5 ];
10
- std::mutex m1;
10
+ std::mutex m1; // NON_COMPLIANT
11
11
12
12
for (int i = 0 ; i < 5 ; ++i) {
13
- threads[i] = std::thread (t1, i, &m1); // NON_COMPLIANT
13
+ threads[i] = std::thread (t1, i, &m1);
14
14
}
15
15
}
16
16
17
17
void f2 () {
18
18
std::thread threads[5 ];
19
- std::mutex m1;
19
+ std::mutex m1; // COMPLIANT - due to check below
20
20
21
21
for (int i = 0 ; i < 5 ; ++i) {
22
- threads[i] = std::thread (t1, i, &m1); // COMPLIANT - due to check below
22
+ threads[i] = std::thread (t1, i, &m1);
23
23
}
24
24
25
25
for (int i = 0 ; i < 5 ; ++i) {
26
26
threads[i].join ();
27
27
}
28
28
}
29
29
30
- std::mutex m2;
30
+ std::mutex m2; // COMPLIANT - since m2 will not go out of scope.
31
31
32
32
void f3 () {
33
33
std::thread threads[5 ];
34
34
35
35
for (int i = 0 ; i < 5 ; ++i) {
36
- threads[i] = std::thread (
37
- t1, i, &m2); // COMPLIANT - since m2 will not go out of scope.
36
+ threads[i] = std::thread (t1, i, &m2);
38
37
}
39
38
}
40
39
41
40
std::mutex *m3;
42
41
43
42
void f4 () {
44
- m3 = new std::mutex ();
43
+ m3 = new std::mutex (); // COMPLIANT
45
44
46
45
std::thread threads[5 ];
47
46
48
47
for (int i = 0 ; i < 5 ; ++i) {
49
- threads[i] = std::thread (t1, i, m3); // COMPLIANT
48
+ threads[i] = std::thread (t1, i, m3);
50
49
}
51
50
52
51
// since we wait here, and the local function created the
@@ -59,22 +58,22 @@ void f4() {
59
58
}
60
59
61
60
void f5 () {
62
- m3 = new std::mutex ();
61
+ m3 = new std::mutex (); // COMPLIANT
63
62
64
63
std::thread threads[5 ];
65
64
66
65
for (int i = 0 ; i < 5 ; ++i) {
67
- threads[i] = std::thread (t2, i, &m3); // COMPLIANT
66
+ threads[i] = std::thread (t2, i, &m3);
68
67
}
69
68
}
70
69
71
70
void f6 () {
72
- m3 = new std::mutex ();
71
+ m3 = new std::mutex (); // COMPLIANT
73
72
74
73
std::thread threads[5 ];
75
74
76
75
for (int i = 0 ; i < 5 ; ++i) {
77
- threads[i] = std::thread (t1, i, m3); // COMPLIANT
76
+ threads[i] = std::thread (t1, i, m3);
78
77
}
79
78
80
79
for (int i = 0 ; i < 5 ; ++i) {
@@ -85,13 +84,12 @@ void f6() {
85
84
}
86
85
87
86
void f7 () {
88
- m3 = new std::mutex ();
87
+ m3 = new std::mutex (); // NON_COMPLIANT - t3 will attempt to delete the mutex.
89
88
90
89
std::thread threads[5 ];
91
90
92
91
for (int i = 0 ; i < 5 ; ++i) {
93
- threads[i] = std::thread (
94
- t3, i, m3); // NON_COMPLIANT - t3 will attempt to delete the mutex.
92
+ threads[i] = std::thread (t3, i, m3);
95
93
}
96
94
97
95
for (int i = 0 ; i < 5 ; ++i) {
@@ -100,12 +98,12 @@ void f7() {
100
98
}
101
99
102
100
void f8 () {
103
- std::mutex *m = new std::mutex ();
104
- delete m; // COMPLIANT
101
+ std::mutex *m = new std::mutex (); // COMPLIANT
102
+ delete m;
105
103
}
106
104
107
105
void f9 () {
108
106
std::mutex m; // COMPLIANT
109
107
}
110
108
111
- std::mutex *m4 = new std::mutex();
109
+ std::mutex *m4 = new std::mutex(); // COMPLIANT
0 commit comments