getpwnam_r 内存泄漏

发布于 2024-08-05 08:24:42 字数 1252 浏览 4 评论 0原文

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


==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 释放它的缓冲区?或者我必须抑制这些 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.

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

Thanks, Kasper

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

优雅的叶子 2024-08-12 08:24:42

内存并不是专门为 getpwnam 分配的。相反,它代表 /etc/nsswitch.conf 的配置。 AFAICT,让 libc 释放此内存的唯一方法是通过调用 __libc_freeres:

extern void __libc_freeres (void);

这应该释放 C 库占用的所有内存(而不仅仅是 NSS 占用的内存)。

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);

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文