aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/malloc.c
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-08-08 18:23:31 +0000
committerJordan Rose <jordan_rose@apple.com>2012-08-08 18:23:31 +0000
commit0d53ab4024488d0c6cd283992be3fd4b67099bd3 (patch)
tree2d6a8de8cff82ab71bdcd98a0c649b77fecebffb /test/Analysis/malloc.c
parente0d24eb1060a213ec9820dc02c45f26b2d5b348b (diff)
[analyzer] Track malloc'd regions stored in structs.
The main blocker on this (besides the previous commit) was that ScanReachableSymbols was not looking through LazyCompoundVals. Once that was fixed, it's easy enough to clear out malloc data on return, just like we do when we bind to a global region. <rdar://problem/10872635> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161511 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/malloc.c')
-rw-r--r--test/Analysis/malloc.c48
1 files changed, 23 insertions, 25 deletions
diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c
index 7f5062af45..24fa30baa8 100644
--- a/test/Analysis/malloc.c
+++ b/test/Analysis/malloc.c
@@ -513,20 +513,20 @@ void testMalloc() {
int *x = malloc(12);
StructWithPtr St;
St.memP = x;
- arrOfStructs[0] = St;
+ arrOfStructs[0] = St; // no-warning
}
StructWithPtr testMalloc2() {
int *x = malloc(12);
StructWithPtr St;
St.memP = x;
- return St;
+ return St; // no-warning
}
int *testMalloc3() {
int *x = malloc(12);
int *y = x;
- return y;
+ return y; // no-warning
}
void testElemRegion1() {
@@ -926,31 +926,16 @@ int cmpHeapAllocationToUnknown() {
return 0;
}
-// ----------------------------------------------------------------------------
-// False negatives.
-
-// TODO: This requires tracking symbols stored inside the structs/arrays.
-void testMalloc5() {
- StructWithPtr St;
- StructWithPtr *pSt = &St;
- pSt->memP = malloc(12);
-}
-
-// TODO: This is another false negative.
-void testMallocWithParam(int **p) {
- *p = (int*) malloc(sizeof(int));
- *p = 0;
-}
-
-void testMallocWithParam_2(int **p) {
- *p = (int*) malloc(sizeof(int));
-}
-
-// TODO: This should produce a warning, similar to the previous issue.
void localArrayTest() {
char *p = (char*)malloc(12);
char *ArrayL[12];
- ArrayL[0] = p;
+ ArrayL[0] = p; // expected-warning {{leak}}
+}
+
+void localStructTest() {
+ StructWithPtr St;
+ StructWithPtr *pSt = &St;
+ pSt->memP = malloc(12); // expected-warning{{Memory is never released; potential leak}}
}
// Test double assignment through integers.
@@ -1019,3 +1004,16 @@ int* reallocButNoMalloc(struct HasPtr *a, int c, int size) {
return 0; // expected-warning{{Memory is never released; potential leak}}
return a->p;
}
+
+// ----------------------------------------------------------------------------
+// False negatives.
+
+// TODO: This is another false negative.
+void testMallocWithParam(int **p) {
+ *p = (int*) malloc(sizeof(int));
+ *p = 0;
+}
+
+void testMallocWithParam_2(int **p) {
+ *p = (int*) malloc(sizeof(int));
+}