Skip to content

Commit 5931a97

Browse files
committed
CPP: Add a test of a template instantiation where the destructor is never called.
1 parent f20af49 commit 5931a97

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
| ExternalOwners.cpp:49:3:49:20 | ... = ... | Resource a is acquired by class MyScreen but not released anywhere in this class. |
1212
| ListDelete.cpp:21:3:21:21 | ... = ... | Resource first is acquired by class MyThingColection but not released anywhere in this class. |
1313
| NoDestructor.cpp:23:3:23:20 | ... = ... | Resource n is acquired by class MyClass5 but not released anywhere in this class. |
14+
| NoDestructor.cpp:75:3:75:21 | ... = ... | Resource ptr is acquired by class TemplateWithDestructor<int *> but not released anywhere in this class. |
1415
| PlacementNew.cpp:36:3:36:36 | ... = ... | Resource p1 is acquired by class MyTestForPlacementNew but not released anywhere in this class. |
1516
| SelfRegistering.cpp:25:3:25:24 | ... = ... | Resource side is acquired by class MyOwner but not released anywhere in this class. |
1617
| Variants.cpp:25:3:25:13 | ... = ... | Resource f is acquired by class MyClass4 but not released anywhere in this class. |

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,25 @@ class MyClass7 : public MyClass7Base
6666
n = new MyNumber(200); // GOOD: deleted in base class
6767
}
6868
};
69+
70+
template<class T>
71+
class TemplateWithDestructor
72+
{
73+
public:
74+
TemplateWithDestructor(int len) {
75+
ptr = new char[len]; // GOOD [FALSE POSITIVE]
76+
}
77+
78+
~TemplateWithDestructor()
79+
{
80+
delete [] ptr;
81+
}
82+
83+
private:
84+
char *ptr;
85+
};
86+
87+
void test() {
88+
TemplateWithDestructor<int *> *t_ptr = new TemplateWithDestructor<int *>(10);
89+
//delete t_ptr; --- destructor never used
90+
}

0 commit comments

Comments
 (0)