bug-glibc
[Top][All Lists]
Advanced

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

Memory leak in gethostbyaddr() and getprotobynumber()


From: Phil Dibowitz
Subject: Memory leak in gethostbyaddr() and getprotobynumber()
Date: Tue, 02 Jul 2002 16:37:46 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.4.1) Gecko/20020508 Netscape6/6.2.3

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

}

return(0);
}
------------------END-SAMPLE-C-CODE----------------

Lastly, as far as I've seen, this is not an open-subscription list, but incase I'm painfully blind, and missed it, please CC me on all replies.

Thanks,
Phil Dibowitz
--
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety."
-Benjamin Franklin, 1759




reply via email to

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