This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug network/15048] New: getaddrinfo() leaks memory when /etc/nssswitch.conf is not present.
- From: "jiji.vinitha at gmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Tue, 22 Jan 2013 14:42:03 +0000
- Subject: [Bug network/15048] New: getaddrinfo() leaks memory when /etc/nssswitch.conf is not present.
- Auto-submitted: auto-generated
http://sourceware.org/bugzilla/show_bug.cgi?id=15048
Bug #: 15048
Summary: getaddrinfo() leaks memory when /etc/nssswitch.conf is
not present.
Product: glibc
Version: 2.11
Status: NEW
Severity: normal
Priority: P2
Component: network
AssignedTo: unassigned@sourceware.org
ReportedBy: jiji.vinitha@gmail.com
Classification: Unclassified
Created attachment 6829
--> http://sourceware.org/bugzilla/attachment.cgi?id=6829
patch which fixes the leak
Hi,
Found in glibc-2.11.2 on arm-*-linux-gnueabi target.
The scenario:
When
* /etc/nsswitch.conf is not existing
* gethostbyname() has not been called
* dns server is reachable
* "localhost.localdomain" is not resisted to dns
In the above scenario, getaddrinfo("localhost.localdomain"); is leaking
memory.
The testcase to reproduce this issue
[nsstest.c]
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
int i;
struct addrinfo *res;
int cnt = 2500;
#if 0
if (gethostbyname("localhost.localdomain") == 0) {
}
#endif
for( i = 0; i < cnt; i++ ) {
if( getaddrinfo("localhost.localdomain", NULL, NULL, &res ) == 0 ){
freeaddrinfo(res);
}
write(1, ".", 1);
}
write(1, "done\n", 5);
while(1){sleep(62);}
return 0;
}
How to reproduce the leak
# strace -e open ./nsstest
...
.open("/etc/nsswitch.conf", O_RDONLY) = -1 ENOENT (No such file or
directory) <- cause of leak
.open("/etc/nsswitch.conf", O_RDONLY) = -1 ENOENT (No such file or
directory)
.open("/etc/nsswitch.conf", O_RDONLY) = -1 ENOENT (No such file or
directory)
.open("/etc/nsswitch.conf", O_RDONLY) = -1 ENOENT (No such file or
directory)
.open("/etc/nsswitch.conf", O_RDONLY) = -1 ENOENT (No such file or
directory)
.open("/etc/nsswitch.conf", O_RDONLY) = -1 ENOENT (No such file or
directory)
.open("/etc/nsswitch.conf", O_RDONLY) = -1 ENOENT (No such file or
directory)
...
RSS is increasing as shown below while executed the binary
# ./nsstest
............................................................................................................................................................................................................................................................................................................................................................................................................................................................................^Z
[1]+ Stopped ./nsstest
# ps
PID TTY TIME CMD
167 pts/0 00:00:00 bash
284 pts/0 00:00:00 nsstest
285 pts/0 00:00:00 ps
# ps -p 284 u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 284 0.9 0.5 1960 668 pts/0 T 00:29 0:00 ./nsstest
# fg
./nsstest
..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................^Z
[1]+ Stopped ./nsstest
# ps -p 284 u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 284 1.3 0.6 2088 768 pts/0 T 00:29 0:00 ./nsstest
# fg
./nsstest
...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................^Z
[1]+ Stopped ./nsstest
# ps -p 284 u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 284 1.1 0.7 2216 912 pts/0 T 00:29 0:00 ./nsstest
#
The attached patch solved this issue in glibc-2.11.2.
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.