bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gethostbyname_r leaks memory


From: Robert Krüger
Subject: gethostbyname_r leaks memory
Date: Tue, 18 Mar 2003 14:02:18 +0100

>Submitter-Id:  net
>Originator:    Robert Krüger
>Organization:  Kiwilogic.com AG
>Confidential:  no
>Synopsis:      gethostbyname_r leaks memory
>Severity:      
>Priority:      
>Category:      libc
>Class:         
>Release:       libc-2.2.4
>Environment:
        
Host type: i486-suse-linux-gnu
System: Linux klinux 2.4.16 #10 SMP Tue Dec 18 17:15:31 CET 2001 i686
unknown
Architecture: i686

Addons: db db2 linuxthreads noversion
Build CFLAGS: -O2 -mcpu=i486 -march=i486 -g
Build CC: gcc
Compiler version: 2.95.3 20010315 (SuSE)
Kernel headers: UTS_RELEASE
Symbol versioning: yes
Build static: yes
Build shared: yes
Build pic-default: no
Build profile: yes
Build omitfp: no
Build bounded: no
Build static-nss: no
Stdio: libio

/etc/hosts.order:
order hosts, bind
multi on

/etc/hosts.conf:
hosts: files dns

>Description:
gethostbyname_r (as well as gethostbyname, gethostbyaddr_r, maybe
other of this family) leak memory when repeating the following:
1. create new thread
2. within thread, call gethostbyname_r with a hostname not listed
   in /etc/hosts
3. exit thread

>How-To-Repeat:
        Compile the test program below with -lpthread and run.
        It executes step 1 to 3 from above in an endless loop and keeps
        growing. 
        If compiled with symbol THREADED not defined (comment out line
        10), only step 2 from above is executed in the loop and the
        process size stays constant.
        Also if calling gethostbyname_r with a dotted IP address
        instead of a hostname (uncomment line 14, comment line 15),
        the process size stays constant.


#define _REENTRANT


#include <pthread.h>
#include <netdb.h>
#include <resolv.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#define THREADED

static void* thread( void* dummy )
{
//  static char*      host = "192.168.0.9";
  static char*      host = "www.gnu.org";
  struct hostent    HE, *pHE;
  char              acBuf[10240];
  int               iH_Errno;

  gethostbyname_r (host, &HE, acBuf, sizeof(acBuf), &pHE, &iH_Errno);
  
  return NULL;
}

int main()
{
  pthread_t id;

  for (;;)
  {
#ifdef THREADED
    pthread_create( &id, NULL, thread, NULL );
    pthread_join( id, NULL );
#else
    thread( NULL );
#endif
  }

  return 0;
}


>Fix:
        No fix known. Calling endhostend(3) after gethostbyname_r does
        not help.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]