Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 05 Aug 2006 13:35:45 +0400
From:      "Igor A. Valcov" <viaprog@betline.ru>
To:        freebsd-hackers@freebsd.org
Subject:   pthreads memoty leak?
Message-ID:  <op.tds0xvrxonyo0y@s4.hibet.ru>

next in thread | raw e-mail | index | archive | help

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.

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=


#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 =3D 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 =3D 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 =3D 0; i < 10000000; i++) {

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

          threaded();
      }

      printf ("FINISHED.\n");

      sleep (3600);

      return 0;
}

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D

-- =

Igor A. Valcov



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?op.tds0xvrxonyo0y>