tech-userlevel archive

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

Possible pthreads memory leak

Hello everyone,

So I'm hunting down a memory leak, and I notice that it occurs only
when the program is threaded. I reproduced it with the simple threaded
program below, which simply creates and joins threads repeatedly. At
any point in time, there will be no more than two threads running. Its
memory usage continuously grows, pretty quickly in fact:

19411 zach      25    0   589M 4416K RUN/1      0:22  0.00% 21.00% a.out

This is on NetBSD 5.0.1-amd64. I assume this is a bug in the pthread library...?


...and the program:

#include <pthread.h>
#include <stdio.h>

void *test(void *n)

    return NULL;

int main(int argc, char **argv)
    pthread_t tid;
    void *x;
    int r;

    while (1) {
        pthread_create(&tid, NULL, test, NULL);
        r = pthread_join(tid, &x);
        if (r)

    return 0;

Home | Main Index | Thread Index | Old Index