@@ -7,46 +7,45 @@ void t3(int i, std::mutex *pm) { delete pm; }
77
88void f1 () {
99 std::thread threads[5 ];
10- std::mutex m1;
10+ std::mutex m1; // NON_COMPLIANT
1111
1212 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);
1414 }
1515}
1616
1717void f2 () {
1818 std::thread threads[5 ];
19- std::mutex m1;
19+ std::mutex m1; // COMPLIANT - due to check below
2020
2121 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);
2323 }
2424
2525 for (int i = 0 ; i < 5 ; ++i) {
2626 threads[i].join ();
2727 }
2828}
2929
30- std::mutex m2;
30+ std::mutex m2; // COMPLIANT - since m2 will not go out of scope.
3131
3232void f3 () {
3333 std::thread threads[5 ];
3434
3535 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);
3837 }
3938}
4039
4140std::mutex *m3;
4241
4342void f4 () {
44- m3 = new std::mutex ();
43+ m3 = new std::mutex (); // COMPLIANT
4544
4645 std::thread threads[5 ];
4746
4847 for (int i = 0 ; i < 5 ; ++i) {
49- threads[i] = std::thread (t1, i, m3); // COMPLIANT
48+ threads[i] = std::thread (t1, i, m3);
5049 }
5150
5251 // since we wait here, and the local function created the
@@ -59,22 +58,22 @@ void f4() {
5958}
6059
6160void f5 () {
62- m3 = new std::mutex ();
61+ m3 = new std::mutex (); // COMPLIANT
6362
6463 std::thread threads[5 ];
6564
6665 for (int i = 0 ; i < 5 ; ++i) {
67- threads[i] = std::thread (t2, i, &m3); // COMPLIANT
66+ threads[i] = std::thread (t2, i, &m3);
6867 }
6968}
7069
7170void f6 () {
72- m3 = new std::mutex ();
71+ m3 = new std::mutex (); // COMPLIANT
7372
7473 std::thread threads[5 ];
7574
7675 for (int i = 0 ; i < 5 ; ++i) {
77- threads[i] = std::thread (t1, i, m3); // COMPLIANT
76+ threads[i] = std::thread (t1, i, m3);
7877 }
7978
8079 for (int i = 0 ; i < 5 ; ++i) {
@@ -85,13 +84,12 @@ void f6() {
8584}
8685
8786void f7 () {
88- m3 = new std::mutex ();
87+ m3 = new std::mutex (); // NON_COMPLIANT - t3 will attempt to delete the mutex.
8988
9089 std::thread threads[5 ];
9190
9291 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);
9593 }
9694
9795 for (int i = 0 ; i < 5 ; ++i) {
@@ -100,12 +98,12 @@ void f7() {
10098}
10199
102100void f8 () {
103- std::mutex *m = new std::mutex ();
104- delete m; // COMPLIANT
101+ std::mutex *m = new std::mutex (); // COMPLIANT
102+ delete m;
105103}
106104
107105void f9 () {
108106 std::mutex m; // COMPLIANT
109107}
110108
111- std::mutex *m4 = new std::mutex();
109+ std::mutex *m4 = new std::mutex(); // COMPLIANT
0 commit comments