diff options
author | Anna Zaks <ganna@apple.com> | 2012-08-03 18:30:18 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2012-08-03 18:30:18 +0000 |
commit | 52242a667795fd61ff3ea95b33a71ceafaad1d2a (patch) | |
tree | 4f64c47322fbfb775b3e1a6eb1e22e5444ba1e1b /clang/test/Analysis | |
parent | aca09de378ff4f5d87de2a75f14f9f9f650553c1 (diff) | |
download | bcm5719-llvm-52242a667795fd61ff3ea95b33a71ceafaad1d2a.tar.gz bcm5719-llvm-52242a667795fd61ff3ea95b33a71ceafaad1d2a.zip |
[analyzer] Malloc: track non-allocated but freed memory
There is no reason why we should not track the memory which was not
allocated in the current function, but was freed there. This would
allow to catch more use-after-free and double free with no/limited IPA.
Also fix a realloc issue which surfaced as the result of this patch.
llvm-svn: 161248
Diffstat (limited to 'clang/test/Analysis')
-rw-r--r-- | clang/test/Analysis/malloc.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c index 377642cc58c..964424647f6 100644 --- a/clang/test/Analysis/malloc.c +++ b/clang/test/Analysis/malloc.c @@ -69,7 +69,7 @@ void reallocSizeZero1() { char *p = malloc(12); char *r = realloc(p, 0); if (!r) { - free(p); + free(p); // expected-warning {{Attempt to free released memory}} } else { free(r); } @@ -79,7 +79,7 @@ void reallocSizeZero2() { char *p = malloc(12); char *r = realloc(p, 0); if (!r) { - free(p); + free(p); // expected-warning {{Attempt to free released memory}} } else { free(r); } @@ -321,7 +321,7 @@ void nullFree() { void paramFree(int *p) { myfoo(p); free(p); // no warning - myfoo(p); // TODO: This should be a warning. + myfoo(p); // expected-warning {{Use of memory after it is freed}} } int* mallocEscapeRet() { @@ -999,3 +999,11 @@ void foo (xpc_connection_t peer) { xpc_connection_resume(peer); } +// Make sure we catch errors when we free in a function which does not allocate memory. +void freeButNoMalloc(int *p, int x){ + if (x) { + free(p); + //user forgot a return here. + } + free(p); // expected-warning {{Attempt to free released memory}} +} |