CPP: Add similar test cases with function pointers.

This commit is contained in:
Geoffrey White
2018-12-12 10:06:06 +00:00
parent 77c1ad47f9
commit 8e2459a6b7
2 changed files with 24 additions and 2 deletions

View File

@@ -13,6 +13,8 @@
| Lambda.cpp:7:3:7:21 | ... = ... | Resource r1 is acquired by class testLambda but not released anywhere in this class. |
| Lambda.cpp:12:3:12:21 | ... = ... | Resource r2 is acquired by class testLambda but not released anywhere in this class. |
| Lambda.cpp:24:3:24:21 | ... = ... | Resource r4 is acquired by class testLambda but not released anywhere in this class. |
| Lambda.cpp:26:3:26:21 | ... = ... | Resource r5 is acquired by class testLambda but not released anywhere in this class. |
| 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. |
| ListDelete.cpp:21:3:21:21 | ... = ... | Resource first is acquired by class MyThingColection but not released anywhere in this class. |
| NoDestructor.cpp:23:3:23:20 | ... = ... | Resource n is acquired by class MyClass5 but not released anywhere in this class. |
| PlacementNew.cpp:36:3:36:36 | ... = ... | Resource p1 is acquired by class MyTestForPlacementNew but not released anywhere in this class. |

View File

@@ -22,15 +22,35 @@ public:
deleter3();
r4 = new char[4096]; // BAD
r5 = new char[4096]; // GOOD [FALSE POSITIVE]
deleter5 = &deleter_for_r5;
r6 = new char[4096]; // GOOD [FALSE POSITIVE]
deleter6 = &testLambda::deleter_for_r6;
}
static void deleter_for_r5(char *r)
{
delete [] r;
}
void deleter_for_r6()
{
delete [] r6;
}
~testLambda()
{
deleter1(r1);
deleter5(r5);
((*this).*deleter6)();
}
private:
char *r1, *r2, *r3, *r4;
char *r1, *r2, *r3, *r4, *r5, *r6;
void (*deleter1)(char *r);
void (*deleter1)(char *r);
void (*deleter5)(char *r);
void (testLambda::*deleter6)();
};