From fe6eb67b12dbd5243741f1428b14c55db50305d7 Mon Sep 17 00:00:00 2001 From: Anna Zaks Date: Fri, 24 Aug 2012 02:28:20 +0000 Subject: [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 --- clang/test/Analysis/malloc.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'clang/test/Analysis/malloc.c') 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. -- cgit v1.2.3