From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 16 15:19:06 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from green.homeunix.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id D6A7B16A4CE; Wed, 16 Feb 2005 15:19:05 +0000 (GMT) Received: from green.homeunix.org (green@localhost [127.0.0.1]) by green.homeunix.org (8.13.1/8.13.1) with ESMTP id j1GFJ4eF039591; Wed, 16 Feb 2005 10:19:05 -0500 (EST) (envelope-from green@green.homeunix.org) Received: (from green@localhost) by green.homeunix.org (8.13.1/8.13.1/Submit) id j1GFJ4Qc039590; Wed, 16 Feb 2005 10:19:04 -0500 (EST) (envelope-from green) Date: Wed, 16 Feb 2005 10:19:03 -0500 From: Brian Fundakowski Feldman To: Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?= Message-ID: <20050216151903.GD1069@green.homeunix.org> References: <86mzu4sqk5.fsf@xps.des.no> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <86mzu4sqk5.fsf@xps.des.no> User-Agent: Mutt/1.5.6i cc: hackers@freebsd.org Subject: Re: memory leak in resolver X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Feb 2005 15:19:06 -0000 On Wed, Feb 16, 2005 at 12:16:26PM +0100, Dag-Erling Smørgrav wrote: > des@xps ~/src/gai% cat gai.c > #include > #include > #include > #include > > int > main(void) > { > struct addrinfo hint, *res; > > memset(&hint, 0, sizeof(hint)); > hint.ai_family = AF_INET; > hint.ai_socktype = SOCK_STREAM; > hint.ai_protocol = 0; > if (getaddrinfo("www.freebsd.org", "http", &hint, &res) == 0) > freeaddrinfo(res); > return (0); > } > des@xps ~/src/gai% valgrind --leak-check=yes --num-callers=8 ./gai > ==44998== Memcheck, a memory error detector for x86-linux. > ==44998== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward. > ==44998== Using valgrind-2.1.0, a program supervision framework for x86-linux. > ==44998== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward. > ==44998== Estimated CPU clock rate is 3591 MHz > ==44998== For more details, rerun with: -v > ==44998== > ==44998== > ==44998== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) > ==44998== malloc/free: in use at exit: 2328 bytes in 11 blocks. > ==44998== malloc/free: 45 allocs, 34 frees, 232569 bytes allocated. > ==44998== For counts of detected errors, rerun with: -v > ==44998== searching for pointers to 11 not-freed blocks. > ==44998== checked 1258740 bytes. > ==44998== > ==44998== 49 bytes in 5 blocks are definitely lost in loss record 2 of 5 > ==44998== at 0x3C033173: malloc (vg_replace_malloc.c:105) > ==44998== by 0x3C0D567E: strdup (strdup.c:52) > ==44998== by 0x3C0D0403: _nsyylex (nslexer.l:88) > ==44998== by 0x3C0CF903: _nsyyparse (y.tab.c:380) > ==44998== by 0x3C0D296E: _nsdispatch (nsdispatch.c:353) > ==44998== by 0x3C0C6E33: getaddrinfo (getaddrinfo.c:1646) > ==44998== by 0x804856C: main (gai.c:15) > ==44998== > ==44998== LEAK SUMMARY: > ==44998== definitely lost: 49 bytes in 5 blocks. > ==44998== possibly lost: 0 bytes in 0 blocks. > ==44998== still reachable: 2279 bytes in 6 blocks. > ==44998== suppressed: 0 bytes in 0 blocks. > ==44998== Reachable blocks (those to which a pointer was found) are not shown. > ==44998== To see them, rerun with: --show-reachable=yes > > The amount of memory leaked seems constant regardless of how many > times getaddrinfo() is called, so it's probably from reading > resolv.conf. It looks like the memory leaked scales with the number of times that the mtime of the configuration file changes during the process's lifetime. (Of course, starting at one leak the first time it's used.) -- Brian Fundakowski Feldman \'[ FreeBSD ]''''''''''\ <> green@FreeBSD.org \ The Power to Serve! \ Opinions expressed are my own. \,,,,,,,,,,,,,,,,,,,,,,\