mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Merge pull request #304 from geoffw0/resource-released
CPP: Fix false positive in AV Rule 79.ql
This commit is contained in:
@@ -17,3 +17,5 @@
|
||||
| Variants.cpp:65:3:65:17 | ... = ... | Resource a is acquired by class MyClass6 but not released anywhere in this class. |
|
||||
| Variants.cpp:66:3:66:36 | ... = ... | Resource b is acquired by class MyClass6 but not released anywhere in this class. |
|
||||
| Variants.cpp:67:3:67:41 | ... = ... | Resource c is acquired by class MyClass6 but not released anywhere in this class. |
|
||||
| Wrapped.cpp:46:3:46:22 | ... = ... | Resource ptr2 is acquired by class Wrapped2 but not released anywhere in this class. |
|
||||
| Wrapped.cpp:59:3:59:22 | ... = ... | Resource ptr4 is acquired by class Wrapped2 but not released anywhere in this class. |
|
||||
|
||||
@@ -66,3 +66,25 @@ public:
|
||||
n = new MyNumber(200); // GOOD: deleted in base class
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class TemplateWithDestructor
|
||||
{
|
||||
public:
|
||||
TemplateWithDestructor(int len) {
|
||||
ptr = new char[len]; // GOOD
|
||||
}
|
||||
|
||||
~TemplateWithDestructor()
|
||||
{
|
||||
delete [] ptr;
|
||||
}
|
||||
|
||||
private:
|
||||
char *ptr;
|
||||
};
|
||||
|
||||
void test() {
|
||||
TemplateWithDestructor<int *> *t_ptr = new TemplateWithDestructor<int *>(10);
|
||||
//delete t_ptr; --- destructor never used
|
||||
}
|
||||
|
||||
@@ -37,3 +37,34 @@ public:
|
||||
private:
|
||||
char *ptr1, *ptr2, *ptr3;
|
||||
};
|
||||
|
||||
class Wrapped2
|
||||
{
|
||||
public:
|
||||
Wrapped2(int len) {
|
||||
ptr1 = new char[len]; // GOOD
|
||||
ptr2 = new char[len]; // BAD: not released in destructor
|
||||
|
||||
Init(len);
|
||||
}
|
||||
|
||||
~Wrapped2()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
void Init(int len)
|
||||
{
|
||||
ptr3 = new char[len]; // GOOD
|
||||
ptr4 = new char[len]; // BAD: not released in destructor
|
||||
}
|
||||
|
||||
void Shutdown()
|
||||
{
|
||||
delete [] ptr1;
|
||||
delete [] ptr3;
|
||||
}
|
||||
|
||||
private:
|
||||
char *ptr1, *ptr2, *ptr3, *ptr4;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user