From owner-freebsd-bugs@FreeBSD.ORG Sun Jun 27 03:50:06 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1F21A1065673 for ; Sun, 27 Jun 2010 03:50:06 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id F0FA78FC20 for ; Sun, 27 Jun 2010 03:50:05 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o5R3o5eB002069 for ; Sun, 27 Jun 2010 03:50:05 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o5R3o54E002068; Sun, 27 Jun 2010 03:50:05 GMT (envelope-from gnats) Resent-Date: Sun, 27 Jun 2010 03:50:05 GMT Resent-Message-Id: <201006270350.o5R3o54E002068@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Tiago Natel de Moura (I4K) Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8CCB0106566C for ; Sat, 26 Jun 2010 23:19:00 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 628298FC14 for ; Sat, 26 Jun 2010 23:19:00 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o5QNIx3Y048281 for ; Sat, 26 Jun 2010 23:18:59 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o5QNIx2J048280; Sat, 26 Jun 2010 23:18:59 GMT (envelope-from nobody) Message-Id: <201006262318.o5QNIx2J048280@www.freebsd.org> Date: Sat, 26 Jun 2010 23:18:59 GMT From: Tiago Natel de Moura (I4K) To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: kern/148179: Possible Memory Leak in getaddrinfo() X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Jun 2010 03:50:06 -0000 >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 #include #include #include #include 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: