mirror of
https://github.com/github/codeql.git
synced 2026-05-03 12:45:27 +02:00
C++: Add test case for reassignment to UseAfterFree.ql.
This commit is contained in:
@@ -114,7 +114,7 @@ int main()
|
||||
mc2->method2();
|
||||
delete mc2;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
void *v1 = malloc(100);
|
||||
int *i2 = (int *)malloc(100);
|
||||
@@ -198,3 +198,19 @@ void test_strndupa_dealloc() {
|
||||
char *cpy = strndupa(msg, 4);
|
||||
free(cpy); // BAD [NOT DETECTED]
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
void test_reassignment() {
|
||||
char *a = (char *)malloc(128);
|
||||
char *b = (char *)malloc(128);
|
||||
|
||||
free(a);
|
||||
a[0] = 0; // BAD
|
||||
|
||||
a = b;
|
||||
a[0] = 0; // GOOD
|
||||
|
||||
free(a);
|
||||
a[0] = 0; // BAD
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user