pthreads memoty leak?

Igor A. Valcov viaprog at gmail.com
Sat Aug 5 09:38:49 UTC 2006


Hi

The startup of this program causes memory leak, doesn't it? What's the
reason?

Tested on FreeBSD-6.1 and 5.4 with the same effect.

On Linux work fine.

========================

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

void* mythread(void* arg)
{
       return NULL;
}


void threaded()
{

#define size 1

       int ret, i;

       for (i = 0; i < size; i++) {
           pthread_t t_id;
           pthread_attr_t pthread_attr;

           pthread_attr_init (&pthread_attr);
           pthread_attr_setdetachstate (&pthread_attr,
PTHREAD_CREATE_DETACHED);

           ret = pthread_create (&t_id, &pthread_attr, mythread, NULL);

           pthread_attr_destroy (&pthread_attr);

           if (ret)
               printf ("pthread_create() returned error value %d\n", ret);
       }
}


int main()
{
       int i;

       for (i = 0; i < 10000000; i++) {

           if (i % 1000 == 0)
               printf ("main() iteration: %d\n", i);

           threaded();
       }

       printf ("FINISHED.\n");

       sleep (3600);

       return 0;
}

==============================

-- 
Igor A. Valcov


More information about the freebsd-hackers mailing list