diff options
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() |