Getpwnam_r memory leak

I use getpwnam_r to handle client connections in my programs. Unfortunately, it seems he allocates a buffer that he never frees. Corresponding valgrind output:

==15774== 536 (104 direct, 432 indirect) bytes in 2 blocks are definitely lost in loss record 1 of 3 ==15774== at 0x4C24CFE: malloc (in /usr/lib64/valgrind/amd64-linux/vgpreload_memcheck.so) ==15774== by 0x5143B5A: nss_parse_service_list (in /lib64/libc-2.10.1.so) ==15774== by 0x51442E6: __nss_database_lookup (in /lib64/libc-2.10.1.so) ==15774== by 0x57BE35F: ??? ==15774== by 0x57BF3F6: ??? ==15774== by 0x51014D2: getpwnam_r@ @GLIBC_2.2.5 (in /lib64/libc-2.10.1.so) ==15774== by 0x407906: dopass (auth.c:71) ==15774== by 0x40393E: do_cmd (command.c:127) ==15774== by 0x402496: ftp_main (server.c:58) ==15774== by 0x40224C: handle_client (daemon.c:211) ==15774== by 0x402073: daemon_main (daemon.c:123) ==15774== by 0x4043CC: main (main.c:48) ==15774== ==15774== LEAK SUMMARY: ==15774== definitely lost: 104 bytes in 2 blocks. ==15774== indirectly lost: 432 bytes in 18 blocks. ==15774== possibly lost: 0 bytes in 0 blocks. ==15774== still reachable: 0 bytes in 0 blocks. ==15774== suppressed: 0 bytes in 0 blocks. 

Is there a way to tell getpwnam_r about the release of buffers? Or will I have to suppress these Valgrind errors?

Thanks Kasper

+4
source share
1 answer

The memory is not really allocated specifically for getpwnam. Instead, it presents the configuration /etc/nsswitch.conf . AFAICT, the only way to free libc for this memory is to call __libc_freeres :

 extern void __libc_freeres (void); 

It is intended to free up all the memory on which the C library is stored (and not just the NSS memory).

+7
source

All Articles