getaddrinfo内存泄漏 [英] getaddrinfo memory leak

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

问题描述

我有以下代码可获取有关IPv4地址的信息:

I have this code for getting information about IPv4 address:

struct addrinfo hints, *info = NULL;
char addr4[INET_ADDRSTRLEN];

memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
hints.ai_family = AF_INET;

if (!getaddrinfo(argv[hostPara], NULL, &hints, &info)) {
    inet_ntop(AF_INET, &((const sockaddr_in *)info->ai_addr)->sin_addr, addr4, INET_ADDRSTRLEN);
}
if (info != NULL) {
    freeaddrinfo(info);
}

但是如果我测试argv [hostPara]为"www.google.com",我将从valgrind获取此信息:

but if I tested argv[hostPara] is "www.google.com" I am getting this from valgrind:

==3632== 168 bytes in 1 blocks are still reachable in loss record 1 of 1
==3632==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3632==    by 0x524B5B8: make_request (check_pf.c:249)
==3632==    by 0x524BA53: __check_pf (check_pf.c:342)
==3632==    by 0x5201134: getaddrinfo (getaddrinfo.c:2458)
==3632==    by 0x40186B: main (trace.cc:214)

,并且如果argv[hostPara]"www.ubuntu.com",则没有内存泄漏.这是什么魔术行为?

and if argv[hostPara] is "www.ubuntu.com" there are no memory leaks. What is this magic behaviour?

推荐答案

有点

Looking a bit the gblic, it's about object catching in case of ipv6 (look 249 line).

正如其他成员所解释的那样,仍然可以实现"本身并不是一个错误,但是它可能隐藏了一些错误的情况.在这种情况下,这不是问题,只是警告某些东西可能会隐藏讨厌的东西.

As other members have explained, "still reachable" is not an error itself, but it may hide some buggy situations. In this case it's not a problem, just a warning about something that could hide something nasty.

此警告也已报告给 redhat

警告Google而不是ubuntu的原因是因为google在其服务器上部署了ipv6,而ubuntu却未部署,因此未执行捕获.您可以使用以下方法进行检查:

The reason of the warning for google and not for ubuntu it's beacause google has ipv6 deployed on its servers and ubuntu not, and then the catching is not performed. You can check it with:

nslookup -q=AAAA www.google.com  and nslookup -q=AAAA www.ubuntu.com

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

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