Bug 112208 - memory leak when creating threads with user defined stacksize
Summary: memory leak when creating threads with user defined stacksize
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc
Version: 9
Hardware: i686
OS: Linux
medium
high
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-12-16 08:53 UTC by Thoralf Will
Modified: 2016-11-24 15:03 UTC (History)
1 user (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2004-01-14 15:52:51 UTC
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2004:143 0 normal SHIPPED_LIVE GNU C Library bugfix update 2004-05-11 04:00:00 UTC
Red Hat Product Errata RHBA-2004:212 0 normal SHIPPED_LIVE Updated shadow-utils package available 2004-05-11 04:00:00 UTC
Red Hat Product Errata RHBA-2004:213 0 normal SHIPPED_LIVE Updated ypserv package available 2004-05-11 04:00:00 UTC

Description Thoralf Will 2003-12-16 08:53:15 UTC
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.

Comment 1 Jakub Jelinek 2003-12-17 13:14:04 UTC
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

Comment 2 Jakub Jelinek 2004-01-14 15:52:51 UTC
Fixed in glibc-2.3.2-101.4 in FC1.


Note You need to log in before you can comment on or make changes to this bug.