getpwnam_r内存泄漏 [英] getpwnam_r memory leak

查看:1008
本文介绍了getpwnam_r内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用getpwnam_r来处理我的程序客户端连接。可悲的是,它似乎分配它永远不会释放缓冲区。
有关Valgrind的输出:

I use getpwnam_r to handle client connections in my programs. Sadly enough, it seems to allocate a buffer it never frees. The relevant 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.

伊势有没有办法告诉getpwnam_r释放它的缓冲区?或将我必须要喝preSS这些Valgrind的错误?

Ise there a way to tell getpwnam_r to release it's buffers? Or will I have to suppress these Valgrind errors?

感谢,卡斯帕

推荐答案

内存是不是真的分配给getpwnam明确。相反,它重新presents 的/etc/nsswitch.conf 的配置。 AFAICT,只有这样才能有libc的释放该内存是通过调用 __ libc_freeres

The memory isn't really allocated for getpwnam specifically. Instead, it represents the configuration of /etc/nsswitch.conf. AFAICT, the only way to have libc release this memory is through calling __libc_freeres:

extern void __libc_freeres (void);

这应该释放C库保存到(NSS持有到不只是内存)的所有内存。

This is supposed to release all memory that the C library holds onto (not just the memory NSS holds onto).

这篇关于getpwnam_r内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆