46 lines · cpp
1// Regression test for http://llvm.org/bugs/show_bug.cgi?id=216212// This test relies on timing between threads, so any failures will be flaky.3// RUN: %clangxx_lsan %s -o %t4// RUN: %env_lsan_opts="log_pointers=1:log_threads=1" %run %t5 6// Fixme: remove once test passes with hwasan7// UNSUPPORTED: hwasan8 9#include <assert.h>10#include <pthread.h>11#include <stdio.h>12#include <stdlib.h>13 14pthread_cond_t cond = PTHREAD_COND_INITIALIZER;15pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;16bool flag = false;17 18void *func(void *arg) {19 // This mutex will never be grabbed.20 fprintf(stderr, "entered func()\n");21 pthread_mutex_lock(&mutex);22 free(arg);23 pthread_mutex_unlock(&mutex);24 return 0;25}26 27void create_detached_thread() {28 pthread_t thread_id;29 pthread_attr_t attr;30 31 pthread_attr_init(&attr);32 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);33 34 void *arg = malloc(1337);35 assert(arg);36 // This mutex is never unlocked by the main thread.37 pthread_mutex_lock(&mutex);38 int res = pthread_create(&thread_id, &attr, func, arg);39 assert(res == 0);40 pthread_attr_destroy(&attr);41}42 43int main() {44 create_detached_thread();45}46