Skip to content

Commit 8e2459a

Browse files
committed
CPP: Add similar test cases with function pointers.
1 parent 77c1ad4 commit 8e2459a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

cpp/ql/test/query-tests/jsf/4.10 Classes/AV Rule 79/AV Rule 79.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
| Lambda.cpp:7:3:7:21 | ... = ... | Resource r1 is acquired by class testLambda but not released anywhere in this class. |
1414
| Lambda.cpp:12:3:12:21 | ... = ... | Resource r2 is acquired by class testLambda but not released anywhere in this class. |
1515
| Lambda.cpp:24:3:24:21 | ... = ... | Resource r4 is acquired by class testLambda but not released anywhere in this class. |
16+
| Lambda.cpp:26:3:26:21 | ... = ... | Resource r5 is acquired by class testLambda but not released anywhere in this class. |
17+
| Lambda.cpp:29:3:29:21 | ... = ... | Resource r6 is acquired by class testLambda but not released in the destructor. It is released from deleter_for_r6 on line 40, so this function may need to be called from the destructor. |
1618
| ListDelete.cpp:21:3:21:21 | ... = ... | Resource first is acquired by class MyThingColection but not released anywhere in this class. |
1719
| NoDestructor.cpp:23:3:23:20 | ... = ... | Resource n is acquired by class MyClass5 but not released anywhere in this class. |
1820
| PlacementNew.cpp:36:3:36:36 | ... = ... | Resource p1 is acquired by class MyTestForPlacementNew but not released anywhere in this class. |

cpp/ql/test/query-tests/jsf/4.10 Classes/AV Rule 79/Lambda.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,35 @@ class testLambda
2222
deleter3();
2323

2424
r4 = new char[4096]; // BAD
25+
26+
r5 = new char[4096]; // GOOD [FALSE POSITIVE]
27+
deleter5 = &deleter_for_r5;
28+
29+
r6 = new char[4096]; // GOOD [FALSE POSITIVE]
30+
deleter6 = &testLambda::deleter_for_r6;
31+
}
32+
33+
static void deleter_for_r5(char *r)
34+
{
35+
delete [] r;
36+
}
37+
38+
void deleter_for_r6()
39+
{
40+
delete [] r6;
2541
}
2642

2743
~testLambda()
2844
{
2945
deleter1(r1);
46+
deleter5(r5);
47+
((*this).*deleter6)();
3048
}
3149

3250
private:
33-
char *r1, *r2, *r3, *r4;
51+
char *r1, *r2, *r3, *r4, *r5, *r6;
3452

35-
void (*deleter1)(char *r);
53+
void (*deleter1)(char *r);
54+
void (*deleter5)(char *r);
55+
void (testLambda::*deleter6)();
3656
};

0 commit comments

Comments
 (0)