diff options
author | Anna Zaks <ganna@apple.com> | 2012-02-15 00:11:25 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2012-02-15 00:11:25 +0000 |
commit | ac06814d2f46cb12491b25911e25bb294c65adbf (patch) | |
tree | b6dfebeb3370e7e00d9d4c31270f5885b1c9826c /clang/test/Analysis/malloc.c | |
parent | d51574850eb0bd5c930eb42e57222a73beb7d1f7 (diff) | |
download | bcm5719-llvm-ac06814d2f46cb12491b25911e25bb294c65adbf.tar.gz bcm5719-llvm-ac06814d2f46cb12491b25911e25bb294c65adbf.zip |
[analyzer] Malloc Checker: add support for reallocf, which always frees
the passed in pointer on failure.
llvm-svn: 150533
Diffstat (limited to 'clang/test/Analysis/malloc.c')
-rw-r--r-- | clang/test/Analysis/malloc.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c index dce088e50d9..2d62706ce44 100644 --- a/clang/test/Analysis/malloc.c +++ b/clang/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. |