Bug 112208 - memory leak when creating threads with user defined stacksize
memory leak when creating threads with user defined stacksize
Status: CLOSED ERRATA
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
9
i686 Linux
medium Severity high
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-12-16 03:53 EST by Thoralf Will
Modified: 2016-11-24 10:03 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-01-14 10:52:51 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Thoralf Will 2003-12-16 03:53:15 EST
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 08:14:04 EST
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 10:52:51 EST
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.