Bug 49956

Summary: gethostbyaddr leaking handles when it can't resolve address
Product: [Retired] Red Hat Linux Reporter: Need Real Name <dwinslow>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED WORKSFORME QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2001-08-03 16:50:22 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Need Real Name 2001-07-25 16:55:07 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)

Description of problem:
gethostbyaddr leaks a file handle when it cannot look up the address in 
the /etc/hosts file. Placing the ip in question in the hosts file fixes 
the problem, removing it causes the problem.

char * pr_addr(unsigned int addr)
{
        struct hostent *hp;
        static char buf[80];

        //file handle leak occurs right here when addr not in hosts file
        hp = gethostbyaddr((char *)&addr, 4, AF_INET);

        if ( hp == NULL )
                //sprintf(buf, "%s", inet_ntoa(*(struct in_addr *)&addr));
                sprintf(buf,"pr_addr : could not resolve host.\n");
        else
                sprintf(buf, "%s (%s)", hp->h_name,
                        inet_ntoa(*(struct in_addr *)&addr));
        return(buf);
}


How reproducible:
Always

Steps to Reproduce:
1.See sample code above.
2.
3.
	

Additional info:

Comment 1 Cristian Gafton 2001-07-26 00:59:31 UTC
Move to the right product and component

Comment 2 Jakub Jelinek 2001-08-03 16:50:16 UTC
Which exact glibc version are you using?
How does your /etc/nsswitch.conf look like (does it search dns too, or just
files, or what)?
What exact addresses are you trying (can you cook up a self contained testcase,
not just a single function)?
What does strace show up?

Comment 3 Jakub Jelinek 2001-09-06 17:31:41 UTC
Cannot reproduce this.