我有用于获取有关IPv4地址信息,这样的代码:
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的得到这个:
==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"
没有内存泄漏。 这是什么神奇的行为?