diff options
author | Anna Zaks <ganna@apple.com> | 2012-02-13 20:57:07 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2012-02-13 20:57:07 +0000 |
commit | 30838b994527d12e269abb14d395b1878e78c16d (patch) | |
tree | cc6385ec6c816aaf20392044ec99b3b2af1044ff /test/Analysis/malloc.c | |
parent | 51890355535ec66bc136d6fdd842c2031f541e9d (diff) |
[analyzer] Malloc Checker: realloc: correct the way we are handing the
case when size is 0.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150412 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/malloc.c')
-rw-r--r-- | test/Analysis/malloc.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c index d1d850c681..b819caa0ac 100644 --- a/test/Analysis/malloc.c +++ b/test/Analysis/malloc.c @@ -58,6 +58,57 @@ void reallocFails() { } } +void reallocSizeZero1() { + char *p = malloc(12); + char *r = realloc(p, 0); + if (!r) { + free(p); + } else { + free(r); + } +} + +void reallocSizeZero2() { + char *p = malloc(12); + char *r = realloc(p, 0); + if (!r) { + free(p); + } else { + free(r); + } + free(p); // expected-warning {{Try to free a memory block that has been released}} +} + +void reallocSizeZero3() { + char *p = malloc(12); + char *r = realloc(p, 0); + free(r); +} + +void reallocSizeZero4() { + char *r = realloc(0, 0); + free(r); +} + +void reallocSizeZero5() { + char *r = realloc(0, 0); +} + +void reallocPtrZero1() { + char *r = realloc(0, 12); // expected-warning {{Allocated memory never released.}} +} + +void reallocPtrZero2() { + char *r = realloc(0, 12); + if (r) + free(r); +} + +void reallocPtrZero3() { + char *r = realloc(0, 12); + free(r); +} + // 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. |