diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-11-15 19:11:43 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-11-15 19:11:43 +0000 |
commit | 63bc186d6ac0b44ba4ec6fccb5f471b05c79b666 (patch) | |
tree | 9002c9a95686003fd8a0ed2875fe5b114d4c4bde /test/Analysis/malloc.c | |
parent | f34a5791c5c9df0348714e275adb09b8cf858460 (diff) |
[analyzer] Report leaks at the closing brace of a function body.
This fixes a few cases where we'd emit path notes like this:
+---+
1| v
p = malloc(len);
^ |2
+---+
In general this should make path notes more consistent and more correct,
especially in cases where the leak happens on the false branch of an if
that jumps directly to the end of the function. There are a couple places
where the leak is reported farther away from the cause; these are usually
cases where there are several levels of nested braces before the end of
the function. This still matches our current behavior for when there /is/
a statement after all the braces, though.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168070 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/malloc.c')
-rw-r--r-- | test/Analysis/malloc.c | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c index 76dd3a8fda..03fc38a73f 100644 --- a/test/Analysis/malloc.c +++ b/test/Analysis/malloc.c @@ -102,8 +102,8 @@ void reallocSizeZero5() { } void reallocPtrZero1() { - char *r = realloc(0, 12); // expected-warning {{Memory is never released; potential leak of memory pointed to by 'r'}} -} + char *r = realloc(0, 12); +} // expected-warning {{Memory is never released; potential leak of memory pointed to by 'r'}} void reallocPtrZero2() { char *r = realloc(0, 12); @@ -128,12 +128,12 @@ void reallocRadar6337483_1() { void reallocRadar6337483_2() { char *buf = malloc(100); char *buf2 = (char*)realloc(buf, 0x1000000); - if (!buf2) { // expected-warning {{Memory is never released; potential leak}} + if (!buf2) { ; } else { free(buf2); } -} +} // expected-warning {{Memory is never released; potential leak}} void reallocRadar6337483_3() { char * buf = malloc(100); @@ -186,8 +186,8 @@ void reallocfRadar6337483_3() { } void reallocfPtrZero1() { - char *r = reallocf(0, 12); // expected-warning {{Memory is never released; potential leak}} -} + char *r = reallocf(0, 12); +} // expected-warning {{Memory is never released; potential leak}} // This case tests that storing malloc'ed memory to a static variable which is @@ -384,13 +384,13 @@ void mallocBindFreeUse() { void mallocEscapeMalloc() { int *p = malloc(12); myfoo(p); - p = malloc(12); // expected-warning{{Memory is never released; potential leak}} -} + p = malloc(12); +} // expected-warning{{Memory is never released; potential leak}} void mallocMalloc() { int *p = malloc(12); - p = malloc(12); // expected-warning {{Memory is never released; potential leak}} -} + p = malloc(12); +} // expected-warning {{Memory is never released; potential leak}} void mallocFreeMalloc() { int *p = malloc(12); @@ -454,8 +454,8 @@ void mallocFailedOrNotLeak() { void mallocAssignment() { char *p = malloc(12); - p = fooRetPtr(); // expected-warning {{leak}} -} + p = fooRetPtr(); +} // expected-warning {{leak}} int vallocTest() { char *mem = valloc(12); @@ -624,8 +624,8 @@ void mallocAssert(int *g) { void doNotInvalidateWhenPassedToSystemCalls(char *s) { char *p = malloc(12); strlen(p); - strcpy(p, s); // expected-warning {{leak}} -} + strcpy(p, s); +} // expected-warning {{leak}} // Rely on the CString checker evaluation of the strcpy API to convey that the result of strcpy is equal to p. void symbolLostWithStrcpy(char *s) { @@ -671,8 +671,8 @@ int *specialMallocWithStruct() { // Test various allocation/deallocation functions. void testStrdup(const char *s, unsigned validIndex) { char *s2 = strdup(s); - s2[validIndex + 1] = 'b';// expected-warning {{Memory is never released; potential leak}} -} + s2[validIndex + 1] = 'b'; +} // expected-warning {{Memory is never released; potential leak}} int testStrndup(const char *s, unsigned validIndex, unsigned size) { char *s2 = strndup(s, size); @@ -780,10 +780,11 @@ void radar10978247_positive(int myValueSize) { buffer = malloc(myValueSize); // do stuff with the buffer - if (buffer == stackBuffer) // expected-warning {{leak}} + if (buffer == stackBuffer) return; -} - + else + return; // expected-warning {{leak}} +} // <rdar://problem/11269741> Previously this triggered a false positive // because malloc() is known to return uninitialized memory and the binding // of 'o' to 'p->n' was not getting propertly handled. Now we report a leak. @@ -819,8 +820,8 @@ void radar11270219(void) { void radar_11358224_test_double_assign_ints_positive_2() { void *ptr = malloc(16); - ptr = ptr; // expected-warning {{leak}} -} + ptr = ptr; +} // expected-warning {{leak}} // Assume that functions which take a function pointer can free memory even if // they are defined in system headers and take the const pointer to the @@ -834,8 +835,8 @@ void r11160612_1() { // Null is passed as callback. void r11160612_2() { char *x = malloc(12); - const_ptr_and_callback(0, x, 12, 0); // expected-warning {{leak}} -} + const_ptr_and_callback(0, x, 12, 0); +} // expected-warning {{leak}} // Callback is passed to a function defined in a system header. void r11160612_4() { @@ -935,14 +936,14 @@ int cmpHeapAllocationToUnknown() { void localArrayTest() { char *p = (char*)malloc(12); char *ArrayL[12]; - ArrayL[0] = p; // expected-warning {{leak}} -} + 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}} -} + pSt->memP = malloc(12); +} // expected-warning{{Memory is never released; potential leak}} // Test double assignment through integers. static long glob; @@ -955,8 +956,8 @@ void test_double_assign_ints() void test_double_assign_ints_positive() { void *ptr = malloc(16); - (void*)(long)(unsigned long)ptr; // expected-warning {{unused}} expected-warning {{leak}} -} + (void*)(long)(unsigned long)ptr; // expected-warning {{unused}} +} // expected-warning {{leak}} void testCGContextNoLeak() |