[PATCH] D31978: Fix memory leaks in address sanitizer darwin tests

Francis Ricci via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 12 07:31:32 PDT 2017


fjricci created this revision.

These leaks are detected by leak sanitizer for darwin.


https://reviews.llvm.org/D31978

Files:
  lib/asan/tests/asan_mac_test_helpers.mm
  test/asan/TestCases/Darwin/malloc_destroy_zone.cc
  test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc
  test/asan/TestCases/Darwin/scribble.cc
  test/asan/TestCases/Darwin/suppressions-darwin.cc
  test/asan/TestCases/Darwin/suppressions-sandbox.cc


Index: test/asan/TestCases/Darwin/suppressions-sandbox.cc
===================================================================
--- test/asan/TestCases/Darwin/suppressions-sandbox.cc
+++ test/asan/TestCases/Darwin/suppressions-sandbox.cc
@@ -18,6 +18,7 @@
                               kCFStringEncodingUTF8, FALSE);  // BOOM
   fprintf(stderr, "Ignored.\n");
   free(a);
+  CFRelease(str);
 }
 
 // CHECK-CRASH: AddressSanitizer: heap-buffer-overflow
Index: test/asan/TestCases/Darwin/suppressions-darwin.cc
===================================================================
--- test/asan/TestCases/Darwin/suppressions-darwin.cc
+++ test/asan/TestCases/Darwin/suppressions-darwin.cc
@@ -27,6 +27,7 @@
                               kCFStringEncodingUTF8, FALSE); // BOOM
   fprintf(stderr, "Ignored.\n");
   free(a);
+  CFRelease(str);
 }
 
 // CHECK-CRASH: AddressSanitizer: heap-buffer-overflow
Index: test/asan/TestCases/Darwin/scribble.cc
===================================================================
--- test/asan/TestCases/Darwin/scribble.cc
+++ test/asan/TestCases/Darwin/scribble.cc
@@ -54,4 +54,5 @@
   fprintf(stderr, "okthxbai!\n");
   // CHECK-SCRIBBLE: okthxbai!
   // CHECK-NOSCRIBBLE: okthxbai!
+  free(my_class_isa);
 }
Index: test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc
===================================================================
--- test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc
+++ test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc
@@ -47,5 +47,9 @@
     memset(mem[i], 'a', 8 * (i % kNumIter));
     free(mem[i]);
   }
+  // Presumably the zone name should be freed during destruction,
+  // but it's leaked unless cleared
+  malloc_set_zone_name(zone, NULL);
+  malloc_destroy_zone(zone);
   return 0;
 }
Index: test/asan/TestCases/Darwin/malloc_destroy_zone.cc
===================================================================
--- test/asan/TestCases/Darwin/malloc_destroy_zone.cc
+++ test/asan/TestCases/Darwin/malloc_destroy_zone.cc
@@ -10,12 +10,17 @@
   fprintf(stderr, "zone = %p\n", zone);
   malloc_set_zone_name(zone, "myzone");
   fprintf(stderr, "name changed\n");
+  // Presumably the zone name should be freed during destruction,
+  // but it's leaked unless cleared
+  malloc_set_zone_name(zone, NULL);
+  fprintf(stderr, "name cleared\n");
   malloc_destroy_zone(zone);
   fprintf(stderr, "done\n");
   return 0;
 }
 
 // CHECK: start
 // CHECK-NEXT: zone = 0x{{.*}}
 // CHECK-NEXT: name changed
+// CHECK-NEXT: name cleared
 // CHECK-NEXT: done
Index: lib/asan/tests/asan_mac_test_helpers.mm
===================================================================
--- lib/asan/tests/asan_mac_test_helpers.mm
+++ lib/asan/tests/asan_mac_test_helpers.mm
@@ -237,4 +237,5 @@
       [[NSURL alloc] initWithString:@"Saved Application State"
                      relativeToURL:base];
   [u release];
+  [base release];
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31978.94966.patch
Type: text/x-patch
Size: 2907 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170412/8c467181/attachment.bin>


More information about the llvm-commits mailing list