mirror of
https://github.com/github/codeql.git
synced 2025-12-22 11:46:32 +01:00
CPP: Tests: AV Rule 79 test cases for calloc, realloc and new.
This commit is contained in:
@@ -54,12 +54,12 @@ public:
|
||||
myFile1 = fopen("file1.txt", "rt"); // GOOD
|
||||
myFile2 = fopen("file2.txt", "rt"); // BAD: not closed in destructor
|
||||
|
||||
myArray1 = (int *)calloc(100, sizeof(int)); // BAD: not freed in destructor
|
||||
myArray2 = new int[100]; // BAD: not deleted in destructor
|
||||
myArray3 = new int[100]; // GOOD: deleted in destructor
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
myPtr7 = (int*)realloc(0, sizeof(int)); // GOOD: freed below (assuming the realloc succeeds)
|
||||
myPtr8 = (int*)realloc(myPtr7, sizeof(int)); // BAD: not freed in destructor
|
||||
}
|
||||
|
||||
~MyClass()
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
delete myPtr1;
|
||||
free(myPtr3);
|
||||
fclose(myFile1);
|
||||
|
||||
delete [] myArray3;
|
||||
}
|
||||
|
||||
void close()
|
||||
@@ -85,6 +85,11 @@ public:
|
||||
AutoPtr<int> myAutoPtr;
|
||||
FILE *myFile1;
|
||||
FILE *myFile2;
|
||||
int *myArray1;
|
||||
int *myArray2;
|
||||
int *myArray3;
|
||||
int *myPtr7;
|
||||
int *myPtr8;
|
||||
};
|
||||
|
||||
int main()
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
| AV Rule 79.cpp:49:3:49:18 | ... = ... | Resource myPtr5 is acquired by class MyClass but not released in the destructor. It is released from close on line 75, so this function may need to be called from the destructor. |
|
||||
| AV Rule 79.cpp:50:3:50:37 | ... = ... | Resource myPtr6 is acquired by class MyClass but not released in the destructor. It is released from close on line 76, so this function may need to be called from the destructor. |
|
||||
| AV Rule 79.cpp:55:3:55:36 | ... = ... | Resource myFile2 is acquired by class MyClass but not released anywhere in this class. |
|
||||
| AV Rule 79.cpp:57:3:57:44 | ... = ... | Resource myArray1 is acquired by class MyClass but not released anywhere in this class. |
|
||||
| AV Rule 79.cpp:58:3:58:25 | ... = ... | Resource myArray2 is acquired by class MyClass but not released anywhere in this class. |
|
||||
| AV Rule 79.cpp:62:3:62:45 | ... = ... | Resource myPtr8 is acquired by class MyClass but not released anywhere in this class. |
|
||||
| Container2.cpp:21:3:21:16 | ... = ... | Resource ptr3 is acquired by class Container2<char> but not released anywhere in this class. |
|
||||
| Container2.cpp:21:3:21:16 | ... = ... | Resource ptr3 is acquired by class Container2<int> but not released anywhere in this class. |
|
||||
| DeleteThis.cpp:56:3:56:24 | ... = ... | Resource ptr10 is acquired by class MyClass3 but not released anywhere in this class. |
|
||||
|
||||
Reference in New Issue
Block a user