Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Problem with -fsanitize=leak and libpthread



Hi!

I was looking for memory leaks in a threaded program using
-fsanitize=leak when I had a weird issue with pthread_join not working
after pthread_cancel.

So I wrote a small test program. When I compile this with leak
detection, it doesn't even start:

==23045==Sanitizer CHECK failed: /usr/src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_thread_registry.cc:284 ((tid)) < ((n_contexts_)) (4294967295, 1)

Any ideas?

To reproduce, install NetBSD/9.99.88/amd64 and do

gcc -g -fsanitize=leak -o join join.c -lpthread
./join

Cheers,
 Thomas
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

void *twait(void *a) {
    sleep(10000);
    return NULL;
}

int main() {
    pthread_t w_t;
    void *foo;
    if (pthread_create(&w_t, NULL, &twait, NULL) != 0) {
	printf("create\n");
	return 1;
    }
    if (pthread_cancel(w_t) != 0) {
	printf("cancel\n");
	return 2;
    }
    if (pthread_join(w_t, &foo) != 0) {
	printf("join\n");
	return 3;
    }
    if (foo == PTHREAD_CANCELED) {
	printf("canceled\n");
	return 4;
    }
    return 0;
}


Home | Main Index | Thread Index | Old Index