From owner-freebsd-hackers@FreeBSD.ORG Thu Jan 28 07:00:21 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D51871065670 for ; Thu, 28 Jan 2010 07:00:21 +0000 (UTC) (envelope-from kientzle@freebsd.org) Received: from monday.kientzle.com (kientzle.com [66.166.149.50]) by mx1.freebsd.org (Postfix) with ESMTP id A1B278FC17 for ; Thu, 28 Jan 2010 07:00:21 +0000 (UTC) Received: (from root@localhost) by monday.kientzle.com (8.14.3/8.14.3) id o0S70Qjh096395; Thu, 28 Jan 2010 07:00:26 GMT (envelope-from kientzle@freebsd.org) Received: from dark.x.kientzle.com (fw2.kientzle.com [10.123.1.2]) by kientzle.com with SMTP id fuxieqtccgfgu9j7nnhb35drme; Thu, 28 Jan 2010 07:00:26 +0000 (UTC) (envelope-from kientzle@freebsd.org) Message-ID: <4B613630.6090307@freebsd.org> Date: Wed, 27 Jan 2010 23:01:04 -0800 From: Tim Kientzle User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.8.1.21) Gecko/20090601 SeaMonkey/1.1.16 MIME-Version: 1.0 To: Brandon Falk References: <4B604B43.7010203@gamozo.org> In-Reply-To: <4B604B43.7010203@gamozo.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: "'freebsd-hackers@freebsd.org'" Subject: Re: Leaks in libc? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jan 2010 07:00:21 -0000 Brandon Falk wrote: > The simple program: > > int main() > { > puts("Apple cider"); > > Yields the following result in valgrind: > > ==4703== HEAP SUMMARY: > ==4703== in use at exit: 4,096 bytes in 1 blocks > ==4703== total heap usage: 1 allocs, 0 frees, 4,096 bytes allocated > ==4703== > ==4703== suppressed: 4,096 bytes in 1 blocks > > Any ideas why the standard libraries are leaking like this? Is it > perhaps a bug with valgrind, or maybe FreeBSD automatically cleans up so > they took the cleanup out of their libc? This particular leak is not at all a cause for concern. Many parts of the system libraries use malloc() to allocate working memory that they deliberately never free. In this particular case, you're seeing a 4096-byte buffer that the stdio system allocates the first time you use it. If you use valgrind a lot, you'll soon learn to just ignore this and several other standard "memory leaks." Generally, memory leaks are a cause for concern only when they accumulate over time. This usually happens only when you have code that leaks memory every time it is used (this particular example doesn't qualify since this buffer is only allocated once regardless of how many times you use the stdio calls) and that code is then used in a very long-running program (such as a window manager or web server). Cheers, Tim