[compiler-rt] r190274 - [ASan] turn on leak checking for ASan tests and fix a few discovered leaks

Alexey Samsonov samsonov at google.com
Sun Sep 8 06:23:29 PDT 2013


Author: samsonov
Date: Sun Sep  8 08:23:29 2013
New Revision: 190274

URL: http://llvm.org/viewvc/llvm-project?rev=190274&view=rev
Log:
[ASan] turn on leak checking for ASan tests and fix a few discovered leaks

Modified:
    compiler-rt/trunk/lib/asan/lit_tests/TestCases/Linux/glob.cc
    compiler-rt/trunk/lib/asan/lit_tests/TestCases/Linux/interception_readdir_r_test.cc
    compiler-rt/trunk/lib/asan/lit_tests/Unit/lit.site.cfg.in
    compiler-rt/trunk/lib/asan/lit_tests/lit.cfg
    compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc
    compiler-rt/trunk/lib/asan/tests/asan_str_test.cc
    compiler-rt/trunk/lib/lit.common.unit.cfg
    compiler-rt/trunk/lib/lit.common.unit.configured.in

Modified: compiler-rt/trunk/lib/asan/lit_tests/TestCases/Linux/glob.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/TestCases/Linux/glob.cc?rev=190274&r1=190273&r2=190274&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/TestCases/Linux/glob.cc (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/TestCases/Linux/glob.cc Sun Sep  8 08:23:29 2013
@@ -22,6 +22,7 @@ int main(int argc, char *argv[]) {
   assert(globbuf.gl_pathc == 2);
   printf("%zu\n", strlen(globbuf.gl_pathv[0]));
   printf("%zu\n", strlen(globbuf.gl_pathv[1]));
+  globfree(&globbuf);
   printf("PASS\n");
   // CHECK: PASS
   return 0;

Modified: compiler-rt/trunk/lib/asan/lit_tests/TestCases/Linux/interception_readdir_r_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/TestCases/Linux/interception_readdir_r_test.cc?rev=190274&r1=190273&r2=190274&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/TestCases/Linux/interception_readdir_r_test.cc (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/TestCases/Linux/interception_readdir_r_test.cc Sun Sep  8 08:23:29 2013
@@ -33,6 +33,7 @@ int main() {
     ++count;
   } while (result != NULL);
   fprintf(stderr, "read %d entries\n", count);
+  closedir(d);
   // CHECK: test1: reading the {{.*}} directory...
   // CHECK-NOT: stack-buffer-overflow
   // CHECK: read {{.*}} entries
@@ -51,6 +52,7 @@ int main() {
     ++count;
   } while (result64 != NULL);
   fprintf(stderr, "read %d entries\n", count);
+  closedir(d);
   // CHECK: test2: reading the {{.*}} directory...
   // CHECK-NOT: stack-buffer-overflow
   // CHECK: read {{.*}} entries

Modified: compiler-rt/trunk/lib/asan/lit_tests/Unit/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/Unit/lit.site.cfg.in?rev=190274&r1=190273&r2=190274&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/Unit/lit.site.cfg.in (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/Unit/lit.site.cfg.in Sun Sep  8 08:23:29 2013
@@ -11,3 +11,6 @@ config.name = 'AddressSanitizer-Unit'
 # it as build directory with ASan unit tests.
 config.test_exec_root = "@ASAN_BINARY_DIR@/tests"
 config.test_source_root = config.test_exec_root
+
+if config.host_os == 'Linux':
+  config.environment['ASAN_OPTIONS'] = 'detect_leaks=1'

Modified: compiler-rt/trunk/lib/asan/lit_tests/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/lit.cfg?rev=190274&r1=190273&r2=190274&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/lit.cfg (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/lit.cfg Sun Sep  8 08:23:29 2013
@@ -82,6 +82,10 @@ config.substitutions.append( ('CHECK-%os
 
 config.available_features.add("asan-" + config.bits + "-bits")
 
+# Turn on leak detection on 64-bit Linux.
+if config.host_os == 'Linux' and config.bits == '64':
+  config.environment['ASAN_OPTIONS'] = 'detect_leaks=1'
+
 # Default test suffixes.
 config.suffixes = ['.c', '.cc', '.cpp']
 

Modified: compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc?rev=190274&r1=190273&r2=190274&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc Sun Sep  8 08:23:29 2013
@@ -654,6 +654,7 @@ TEST(AddressSanitizerInterface, Poisonin
       }
     }
   }
+  free(arr);
 }
 
 TEST(AddressSanitizerInterface, PoisonedRegion) {

Modified: compiler-rt/trunk/lib/asan/tests/asan_str_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_str_test.cc?rev=190274&r1=190273&r2=190274&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_str_test.cc (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_str_test.cc Sun Sep  8 08:23:29 2013
@@ -70,6 +70,7 @@ TEST(AddressSanitizer, WcsLenTest) {
   memcpy(heap_string, L"Hello, World!", hello_size);
   EXPECT_EQ(hello_len, Ident(wcslen(heap_string)));
   EXPECT_DEATH(Ident(wcslen(heap_string + 14)), RightOOBReadMessage(0));
+  free(heap_string);
 }
 
 #ifndef __APPLE__

Modified: compiler-rt/trunk/lib/lit.common.unit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lit.common.unit.cfg?rev=190274&r1=190273&r2=190274&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lit.common.unit.cfg (original)
+++ compiler-rt/trunk/lib/lit.common.unit.cfg Sun Sep  8 08:23:29 2013
@@ -15,6 +15,13 @@ config.test_format = lit.formats.GoogleT
 # Setup test suffixes.
 config.suffixes = []
 
+# Tweak PATH to include llvm tools dir.
+llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
+if (not llvm_tools_dir) or (not os.path.exists(llvm_tools_dir)):
+  lit_config.fatal("Invalid llvm_tools_dir config attribute: %r" % llvm_tools_dir)
+path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
+config.environment['PATH'] = path
+
 # Propagate the temp directory. Windows requires this because it uses \Windows\
 # if none of these are present.
 if 'TMP' in os.environ:

Modified: compiler-rt/trunk/lib/lit.common.unit.configured.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lit.common.unit.configured.in?rev=190274&r1=190273&r2=190274&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lit.common.unit.configured.in (original)
+++ compiler-rt/trunk/lib/lit.common.unit.configured.in Sun Sep  8 08:23:29 2013
@@ -8,6 +8,7 @@ config.llvm_obj_root = "@LLVM_BINARY_DIR
 config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
 config.compiler_rt_src_root = "@COMPILER_RT_SOURCE_DIR@"
 config.llvm_build_mode = "@LLVM_BUILD_MODE@"
+config.host_os = "@HOST_OS@"
 
 # LLVM tools dir and build mode can be passed in lit parameters,
 # so try to apply substitution.





More information about the llvm-commits mailing list