Bug#273051: Memory leak in libc getpwuid() and getgrouplist()
tags 273051 - moreinfo
forwarded 273051 http://sourceware.org/bugzilla/show_bug.cgi?id=2314
found 273051 eglibc/2.11.2-6
clone 273051 -1
retitle -1 suppression: nss_parse_service_list()
reassign -1 valgrind 1:3.6.0~svn11254
severity -1 wishlist
notforwarded -1
tags -1 + upstream
quit
Chaskiel M Grundman wrote:
> I think this is a __libc_freeres problem, since if I run valgrind
> with --run-libc-freeres=no, the relevant blocks are reported as
> being still reachable (in fact, no leaks are reported at all, all
> allocated blocks are reported as still reachable.)
[...]
> (http://sourceware.org/bugzilla/show_bug.cgi?id=2314
Thanks! Reproducing this is pretty easy. In a stock experimental
system:
$ cat test.c
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <stdio.h>
int main(void)
{
struct passwd *pw = getpwuid(getuid());
if (!pw)
return 1;
printf("Hello, %s!\n", pw->pw_gecos);
return 0;
}
$ gcc -g -o test test.c
$ valgrind --leak-check=yes --gen-suppressions=all ./test
[...]
HEAP SUMMARY:
in use at exit: 160 bytes in 11 blocks
total heap usage: 66 allocs, 55 frees, 6,430 bytes allocated
160 (40 direct, 120 indirect) bytes in 1 blocks are definitely lost in loss record 11 of 11
at 0x4023F50: malloc (vg_replace_malloc.c:236)
by 0x4110313: nss_parse_service_list (nsswitch.c:622)
[...]
{
<insert_a_suppression_name_here>
Memcheck:Leak
fun:malloc
fun:nss_parse_service_list
fun:__nss_database_lookup
obj:*
obj:*
fun:getpwuid_r@@GLIBC_2.1.2
fun:getpwuid
fun:main
}
[...]
$ /lib/libc.so.6 | head -1
GNU C Library (Debian EGLIBC 2.11.2-6) stable release version 2.11.2, by Roland McGrath et al.
As Andreas Köhler explains on the upstream bug tracker:
> I think the memory is leaked in
> nis/nis_compat/compat-{grp,initgroups,pwd,spwd}.c. All of them contain static
> service_user *ni, which is initialized by init_nss_interface() ->
> __nss_database_lookup ("group_compat", NULL, "nis", &ni).
> This memory does not seem to be freed by __libc_freeres().
valgrind developers: would it be possible to work around this this for now to
glibc-2.x.supp?
Reply to: