summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/malloc.c
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2013-08-15 17:22:06 +0000
committerJordan Rose <jordan_rose@apple.com>2013-08-15 17:22:06 +0000
commit2f8b0229cb23158fb3122f6ed553a94badbc6e8e (patch)
tree6feda7c64d25899587b4fe73869529a4abfa7cc6 /clang/test/Analysis/malloc.c
parentf66198822f315d7bcc82113fa60b4bb03ca6c285 (diff)
downloadbcm5719-llvm-2f8b0229cb23158fb3122f6ed553a94badbc6e8e.tar.gz
bcm5719-llvm-2f8b0229cb23158fb3122f6ed553a94badbc6e8e.zip
[analyzer] If realloc fails on an escaped region, that region doesn't leak.
When a region is realloc()ed, MallocChecker records whether it was known to be allocated or not. If it is, and the reallocation fails, the original region has to be freed. Previously, when an allocated region escaped, MallocChecker completely stopped tracking it, so a failed reallocation still (correctly) wouldn't require freeing the original region. Recently, however, MallocChecker started tracking escaped symbols, so that if it were freed we could check that the deallocator matched the allocator. This broke the reallocation model for whether or not a symbol was allocated. Now, MallocChecker will actually check if a symbol is owned, and only require freeing after a failed reallocation if it was owned before. PR16730 llvm-svn: 188468
Diffstat (limited to 'clang/test/Analysis/malloc.c')
-rw-r--r--clang/test/Analysis/malloc.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c
index 76f59fda199..83946c83a88 100644
--- a/clang/test/Analysis/malloc.c
+++ b/clang/test/Analysis/malloc.c
@@ -1207,6 +1207,16 @@ void freeMemory() {
}
}
+// PR16730
+void testReallocEscaped(void **memory) {
+ *memory = malloc(47);
+ char *new_memory = realloc(*memory, 47);
+ if (new_memory != 0) {
+ *memory = new_memory;
+ }
+}
+
+
// ----------------------------------------------------------------------------
// False negatives.
OpenPOWER on IntegriCloud