Date: Sat, 26 Jun 2010 23:18:59 GMT From: Tiago Natel de Moura (I4K) <tiago4orion@gmail.com> To: freebsd-gnats-submit@FreeBSD.org Subject: kern/148179: Possible Memory Leak in getaddrinfo() Message-ID: <201006262318.o5QNIx2J048280@www.freebsd.org> Resent-Message-ID: <201006270350.o5R3o54E002068@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 148179 >Category: kern >Synopsis: Possible Memory Leak in getaddrinfo() >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Jun 27 03:50:05 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Tiago Natel de Moura (I4K) >Release: FreeBSD 8.0-RELEASE-p3 i386 >Organization: BugSec >Environment: FreeBSD localhost.localdomain 8.0-RELEASE-p3 FreeBSD 8.0-RELEASE-p3 #0: Wed May 26 05:45:12 UTC 2010 root@i386-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC i386 >Description: The function freeaddrinfo NOT release all the memory allocated by getaddrinfo. I encountered this problem analyzing my code with Valgrind and it shows that after calling freeaddrinfo memory is still allocated. I compiled and ran the same code on Linux (fedora and ubuntu) and they seem all right, no memory allocated at the end. Output of the valgrind in FreeBSD: --- snip --- ==16802== HEAP SUMMARY: ==16802== in use at exit: 4,162 bytes in 6 blocks ==16802== total heap usage: 67 allocs, 61 frees, 231,419 bytes allocated ==16802== ==16802== Searching for pointers to 6 not-freed blocks ==16802== Checked 219,908 bytes ==16802== ==16802== LEAK SUMMARY: ==16802== definitely lost: 0 bytes in 0 blocks ==16802== indirectly lost: 0 bytes in 0 blocks ==16802== possibly lost: 0 bytes in 0 blocks ==16802== still reachable: 4,162 bytes in 6 blocks ==16802== suppressed: 0 bytes in 0 blocks ==16802== Rerun with --leak-check=full to see details of leaked memory --- snip --- Now, output on LINUX: --- snip -- ==5532== HEAP SUMMARY: ==5532== in use at exit: 0 bytes in 0 blocks ==5532== total heap usage: 86 allocs, 86 frees, 9,315 bytes allocated ==5532== ==5532== All heap blocks were freed -- no leaks are possible ==5532== ==5532== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 21 from 10) --5532-- --5532-- used_suppression: 21 dl-hack3-cond-1 --- snip --- I thought that the suppression "dl-hack3-cond-1" who could not be implemented in the ports version of valgrind but it has existed since the 3.3 version and my version is 3.5... >How-To-Repeat: Run the code below: /*****************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <netdb.h> int main() { struct addrinfo hints, *res; int errcode; memset(&hints, 0, sizeof(hints)); hints.ai_family=PF_UNSPEC; hints.ai_socktype=SOCK_STREAM; errcode=getaddrinfo("www.google.com", "http", &hints, &res); if (errcode) { printf("%s\n", gai_strerror(errcode)); exit(1); } freeaddrinfo(res); return 0; } /*****************************************************/ $ valgrind -v ./addrinfo_leak gcc (GCC) 4.2.1 20070719 [FreeBSD] valgrind-3.5.0 >Fix: >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006262318.o5QNIx2J048280>