Go Back   The UNIX and Linux Forums > Top Forums > Programming
.
google site




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 05-07-2009
JEscola JEscola is offline
Registered User
 

Join Date: Aug 2008
Posts: 12
Angry Memory LEAK with pthreads

I have this code...

#include <stdio.h>
#include <iostream>
#include <pthread.h>
static void* cliente(void *datos);

int main()
{
pthread_attr_t tattr;
int ret;
size_t size = PTHREAD_STACK_MIN + 0x0100;
ret = pthread_attr_init(&tattr);
ret = pthread_attr_setstacksize(&tattr, size);
ret= pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_JOINABLE);
ret=0;
pthread_t mythread[401];
while(ret<400)
{
int error=pthread_create((pthread_t *)&mythread[ret],&tattr,cliente,NULL);
if(error==0)pthread_detach((pthread_t)mythread);

ret++;
}

while(true)
{}
}
static void* cliente(void *datos)
{
char *buff=(char *)malloc(100000);
sleep(15);
free(buff);
buff=NULL;
pthread_exit(NULL);

}
When the code finishes I can observe that the virtual memory(report) in the creation of the threads is not liberated after doing a detach, even the memory(report) reserved also...

any body knows this problem???

TIA
Sponsored Links