From Bugzilla Helper: User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007 Description of problem: When creating threads with user defined stacksize a memory leak of 4kB/thread occurs when making a join to destroy the thread. This only occurs with glibc compiled for i686, not with glibc for i386. I assume that the bug is caused by the nptl-patch. Version-Release number of selected component (if applicable): glibc-2.3.2 (all releases) How reproducible: Always Steps to Reproduce: The following code example shows the problem. Simply use top to watch the memory usage or do a cat at /proc/pid/mem. ---begin example code--- #include <stdio.h> #include <pthread.h> #include <unistd.h> #include <sys/types.h> #include <time.h> #include <sys/mman.h> void* th_func1(void *); main(int argc, char** argv) { pthread_t th; int i,StackSize=65535; pthread_attr_t Attributes; void* Stack[100]; for (i=0; i<100; i++) Stack[i] = (void*)malloc(StackSize); printf("Starting in 10 seconds.\npid = %d\n",getpid()); sleep(10); printf("Starting...\n"); for (i = 0; i < 100000; i++) { pthread_attr_init(&Attributes); pthread_attr_setstack(&Attributes,Stack[i%100],StackSize); if ( pthread_create(&th, &Attributes, th_func1, (void*) "Th1") != 0) { printf("Can't create thread!"); } else { pthread_join(th, NULL); } } printf("\n... finished.\n"); printf("waiting 20 more seconds.\n"); sleep(20); for (i=0; i<100; i++) free(Stack[i]); } void* th_func1(void *X) { return NULL; } ---end example code--- Actual Results: Memory usage rises until server runs out of (virtual) memory. Expected Results: Memory should get freed (completely) when thread gets destroyed.
You forgot to mention you're using linuxthreads, which is not the default threading library. Fixed thusly: http://sources.redhat.com/ml/libc-hacker/2003-12/msg00069.html
Fixed in glibc-2.3.2-101.4 in FC1.