bug-glibc
[Top][All Lists]
Advanced

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

Re: Memory leak in gethostbyaddr() and getprotobynumber()


From: Andreas Jaeger
Subject: Re: Memory leak in gethostbyaddr() and getprotobynumber()
Date: Thu, 04 Jul 2002 14:20:13 +0200
User-agent: Gnus/5.090007 (Oort Gnus v0.07) XEmacs/21.4 (Artificial Intelligence, i386-suse-linux)

Phil Dibowitz <address@hidden> writes:

> I believe there is a bug in both gethostbyaddr and getprotobynumber
> (and possibly their counterparts).
>
> Below is a sample program that uses both of them and gives a memory
> leak. Let me know if I am mistaken, or using them incorrectly,
> etc... For the record, I've wittnessed this on two systems:
>
> RedHat 7.1, custom kernel: 2.4.18
> glibc-2.2.4-24
> compat-glibc-6.2-2.1.3.2
> glibc-common-2.2.4-24
> glibc-devel-2.2.4-24
>
> Debian Testing, custom kernel: 2.4.18
> ii  libc6          2.2.5-6        GNU C Library: Shared libraries and Timezone
> ii  libc6-dev      2.2.5-6        GNU C Library: Development Libraries and Hea
>
> Here is the sample code. I compiled with:
> gcc -g -Wall -o leak leak.c
>
> ------------------BEGIN-SAMPLE-C-CODE----------------
> #include <stdio.h>
> #include <netdb.h>
> #include <arpa/inet.h>
> #include <unistd.h>
>
> int main() {
>
> struct hostent *hostinfo;
> struct protoent *protoinfo;
> struct in_addr addy;
> int i=0;
> char *foo="127.0.0.1";
> inet_aton(foo,&addy);
>
> for (i=0;i<10000;i++) {
>          hostinfo = gethostbyaddr(&addy,sizeof(addy), AF_INET);
>          protoinfo = getprotobynumber(6);
>          usleep( 1L * 1000UL );

There's no memory leak here.  gethostbyaddr allocates internal memory
and that's ok.


>
> }
>
> return(0);
> }
> ------------------END-SAMPLE-C-CODE----------------
>
> Lastly, as far as I've seen, this is not an open-subscription list,

it is open for everybody,

Andreas

> but incase I'm painfully blind, and missed it, please CC me on all
> replies.
>
> Thanks,
> Phil Dibowitz

-- 
 Andreas Jaeger
  SuSE Labs address@hidden
   private address@hidden
    http://www.suse.de/~aj



reply via email to

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