Index: test/asan/TestCases/Linux/stress_dtls.c =================================================================== --- test/asan/TestCases/Linux/stress_dtls.c +++ test/asan/TestCases/Linux/stress_dtls.c @@ -78,17 +78,18 @@ num_libs = atoi(argv[2]); assert(num_libs <= MAX_N_FUNCTIONS); + void* handles[MAX_N_FUNCTIONS]; int lib; for (lib = 0; lib < num_libs; lib++) { char buf[4096]; snprintf(buf, sizeof(buf), "%s-f%d.so", argv[0], lib); - void *handle = dlopen(buf, RTLD_LAZY); - if (!handle) { + handles[lib] = dlopen(buf, RTLD_LAZY); + if (!handles[lib]) { fprintf(stderr, "%s\n", dlerror()); exit(1); } snprintf(buf, sizeof(buf), "f%d", lib); - Functions[lib] = (f_t)dlsym(handle, buf); + Functions[lib] = (f_t)dlsym(handles[lib], buf); if (!Functions[lib]) { fprintf(stderr, "%s\n", dlerror()); exit(1); @@ -104,6 +105,12 @@ pthread_join(t, 0); } } + + // Close all loaded libs to prevent the possible TLS leak described in + // https://sourceware.org/bugzilla/show_bug.cgi?id=12650. + for (lib = 0; lib < num_libs; lib++) + dlclose(handles[lib]); + return 0; } #else // SO_NAME