summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
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