summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2012-08-24 02:28:20 +0000
committerAnna Zaks <ganna@apple.com>2012-08-24 02:28:20 +0000
commitfe6eb67b12dbd5243741f1428b14c55db50305d7 (patch)
tree38521919e1191d46776daee7870a70c9328c9249 /clang/test
parenta83b6cf2446ebba78ec38564b7021da08187ed4b (diff)
downloadbcm5719-llvm-fe6eb67b12dbd5243741f1428b14c55db50305d7.tar.gz
bcm5719-llvm-fe6eb67b12dbd5243741f1428b14c55db50305d7.zip
[analyzer] Fix realloc related bug in the malloc checker.
When reallocation of a non-allocated (not owned) symbol fails do not expect it to be freed. llvm-svn: 162533
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Analysis/malloc.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c
index e3d92d9ad67..e7368af3f55 100644
--- a/clang/test/Analysis/malloc.c
+++ b/clang/test/Analysis/malloc.c
@@ -1000,17 +1000,26 @@ void freeButNoMalloc(int *p, int x){
}
struct HasPtr {
- int *p;
+ char *p;
};
-int* reallocButNoMalloc(struct HasPtr *a, int c, int size) {
+char* reallocButNoMalloc(struct HasPtr *a, int c, int size) {
int *s;
- a->p = (int *)realloc(a->p, size);
- if (a->p == 0)
- return 0; // expected-warning{{Memory is never released; potential leak}}
+ char *b = realloc(a->p, size);
+ char *m = realloc(a->p, size); // expected-warning {{Attempt to free released memory}}
return a->p;
}
+// We should not warn in this case since the caller will presumably free a->p in all cases.
+int reallocButNoMallocPR13674(struct HasPtr *a, int c, int size) {
+ int *s;
+ char *b = realloc(a->p, size);
+ if (b == 0)
+ return -1;
+ a->p = b;
+ return 0;
+}
+
// ----------------------------------------------------------------------------
// False negatives.
OpenPOWER on IntegriCloud