diff options
Diffstat (limited to 'test/Analysis/malloc.c')
-rw-r--r-- | test/Analysis/malloc.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c index dce088e50d..2d62706ce4 100644 --- a/test/Analysis/malloc.c +++ b/test/Analysis/malloc.c @@ -6,6 +6,7 @@ void *malloc(size_t); void *valloc(size_t); void free(void *); void *realloc(void *ptr, size_t size); +void *reallocf(void *ptr, size_t size); void *calloc(size_t nmemb, size_t size); void myfoo(int *p); @@ -151,6 +152,39 @@ void reallocRadar6337483_4() { } } +int *reallocfTest1() { + int *q = malloc(12); + q = reallocf(q, 20); + return q; // no warning - returning the allocated value +} + +void reallocfRadar6337483_4() { + char *buf = malloc(100); + char *buf2 = (char*)reallocf(buf, 0x1000000); + if (!buf2) { + return; // no warning - reallocf frees even on failure + } else { + free(buf2); + } +} + +void reallocfRadar6337483_3() { + char * buf = malloc(100); + char * tmp; + tmp = (char*)reallocf(buf, 0x1000000); + if (!tmp) { + free(buf); // expected-warning {{Try to free a memory block that has been released}} + return; + } + buf = tmp; + free(buf); +} + +void reallocfPtrZero1() { + char *r = reallocf(0, 12); // expected-warning {{Allocated memory never released.}} +} + + // This case tests that storing malloc'ed memory to a static variable which is // then returned is not leaked. In the absence of known contracts for functions // or inter-procedural analysis, this is a conservative answer. |