From e9438b35aad80b2bf36ce93d6d0d879a3ccc2070 Mon Sep 17 00:00:00 2001 From: Francis Ricci Date: Wed, 12 Apr 2017 17:31:41 +0000 Subject: [PATCH] Fix memory leaks in address sanitizer darwin tests Summary: These leaks are detected by leak sanitizer for darwin. Reviewers: glider, kubamracek, kcc, alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D31978 llvm-svn: 300080 --- compiler-rt/lib/asan/tests/asan_mac_test_helpers.mm | 1 + .../test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc | 1 + compiler-rt/test/asan/TestCases/Darwin/scribble.cc | 1 + compiler-rt/test/asan/TestCases/Darwin/suppressions-darwin.cc | 1 + compiler-rt/test/asan/TestCases/Darwin/suppressions-sandbox.cc | 1 + 5 files changed, 5 insertions(+) diff --git a/compiler-rt/lib/asan/tests/asan_mac_test_helpers.mm b/compiler-rt/lib/asan/tests/asan_mac_test_helpers.mm index a7e4b9d1928b..3f8fa26d95b8 100644 --- a/compiler-rt/lib/asan/tests/asan_mac_test_helpers.mm +++ b/compiler-rt/lib/asan/tests/asan_mac_test_helpers.mm @@ -237,4 +237,5 @@ void TestNSURLDeallocation() { [[NSURL alloc] initWithString:@"Saved Application State" relativeToURL:base]; [u release]; + [base release]; } diff --git a/compiler-rt/test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc b/compiler-rt/test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc index 2c643bc03c52..b9b96ef0504e 100644 --- a/compiler-rt/test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc +++ b/compiler-rt/test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc @@ -47,5 +47,6 @@ int main() { memset(mem[i], 'a', 8 * (i % kNumIter)); free(mem[i]); } + malloc_destroy_zone(zone); return 0; } diff --git a/compiler-rt/test/asan/TestCases/Darwin/scribble.cc b/compiler-rt/test/asan/TestCases/Darwin/scribble.cc index 33f64e19ca42..0ddee6b5eef5 100644 --- a/compiler-rt/test/asan/TestCases/Darwin/scribble.cc +++ b/compiler-rt/test/asan/TestCases/Darwin/scribble.cc @@ -54,4 +54,5 @@ int main() { fprintf(stderr, "okthxbai!\n"); // CHECK-SCRIBBLE: okthxbai! // CHECK-NOSCRIBBLE: okthxbai! + free(my_class_isa); } diff --git a/compiler-rt/test/asan/TestCases/Darwin/suppressions-darwin.cc b/compiler-rt/test/asan/TestCases/Darwin/suppressions-darwin.cc index a177c4e17ec4..8c207b102cb0 100644 --- a/compiler-rt/test/asan/TestCases/Darwin/suppressions-darwin.cc +++ b/compiler-rt/test/asan/TestCases/Darwin/suppressions-darwin.cc @@ -27,6 +27,7 @@ int main() { kCFStringEncodingUTF8, FALSE); // BOOM fprintf(stderr, "Ignored.\n"); free(a); + CFRelease(str); } // CHECK-CRASH: AddressSanitizer: heap-buffer-overflow diff --git a/compiler-rt/test/asan/TestCases/Darwin/suppressions-sandbox.cc b/compiler-rt/test/asan/TestCases/Darwin/suppressions-sandbox.cc index ddbad466f7bf..c0b84addaa81 100644 --- a/compiler-rt/test/asan/TestCases/Darwin/suppressions-sandbox.cc +++ b/compiler-rt/test/asan/TestCases/Darwin/suppressions-sandbox.cc @@ -18,6 +18,7 @@ int main() { kCFStringEncodingUTF8, FALSE); // BOOM fprintf(stderr, "Ignored.\n"); free(a); + CFRelease(str); } // CHECK-CRASH: AddressSanitizer: heap-buffer-overflow