Bug 112208 - memory leak when creating threads with user defined stacksize
memory leak when creating threads with user defined stacksize
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
i686 Linux
medium Severity high
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
Depends On:
  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:
Last Closed: 2004-01-14 10:52:51 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2004:143 normal SHIPPED_LIVE GNU C Library bugfix update 2004-05-11 00:00:00 EDT
Red Hat Product Errata RHBA-2004:212 normal SHIPPED_LIVE Updated shadow-utils package available 2004-05-11 00:00:00 EDT
Red Hat Product Errata RHBA-2004:213 normal SHIPPED_LIVE Updated ypserv package available 2004-05-11 00:00:00 EDT

  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)

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:

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());
  for (i = 0; i < 100000; i++) {


    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");
  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)

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:
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.