diff options
author | Anna Zaks <ganna@apple.com> | 2012-05-18 01:16:10 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2012-05-18 01:16:10 +0000 |
commit | 46d01605ee7ae986e4d6f47aa88224e7e8b7146c (patch) | |
tree | 9ea28c64dfbe9e8c0ab403cc496dc1e4945b5b67 /clang/test/Analysis/malloc.c | |
parent | aa739093dfb79fae9fdc44310d69e8bf3ff1cb3e (diff) | |
download | bcm5719-llvm-46d01605ee7ae986e4d6f47aa88224e7e8b7146c.tar.gz bcm5719-llvm-46d01605ee7ae986e4d6f47aa88224e7e8b7146c.zip |
[analyzer]Malloc: refactor and report use after free by memory
allocating functions.
llvm-svn: 157037
Diffstat (limited to 'clang/test/Analysis/malloc.c')
-rw-r--r-- | clang/test/Analysis/malloc.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c index 3257d3d95a5..d0d095b1d4c 100644 --- a/clang/test/Analysis/malloc.c +++ b/clang/test/Analysis/malloc.c @@ -8,6 +8,8 @@ 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); +char *strdup(const char *s); +char *strndup(const char *s, size_t n); void myfoo(int *p); void myfooint(int p); @@ -243,6 +245,12 @@ void f7() { x[0] = 'a'; // expected-warning{{Use of memory after it is freed}} } +void f8() { + char *x = (char*) malloc(4); + free(x); + char *y = strndup(x, 4); // expected-warning{{Use of memory after it is freed}} +} + void f7_realloc() { char *x = (char*) malloc(4); realloc(x,0); @@ -653,10 +661,6 @@ int *specialMallocWithStruct() { } // Test various allocation/deallocation functions. - -char *strdup(const char *s); -char *strndup(const char *s, size_t n); - void testStrdup(const char *s, unsigned validIndex) { char *s2 = strdup(s); s2[validIndex + 1] = 'b';// expected-warning {{Memory is never released; potential leak}} |