From owner-freebsd-questions@FreeBSD.ORG Tue Mar 29 08:00:09 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 06FEF1065674 for ; Tue, 29 Mar 2011 08:00:09 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mail-wy0-f182.google.com (mail-wy0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id 922368FC17 for ; Tue, 29 Mar 2011 08:00:08 +0000 (UTC) Received: by wyf23 with SMTP id 23so4162539wyf.13 for ; Tue, 29 Mar 2011 01:00:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eitanadler.com; s=0xdeadbeef; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=1NkMl5XEtYNWBNVUz6FpsQuEjvv7VjnCTkBXlgtpqA8=; b=C+X1zzfRPYPqF7c9yMp0UJk8WproDq9UpAcmCiPiFrC1Utg3aK0GqKp8C9O0joniiU /GUVZqSfxrpTC6G2ZeWbX1RkXhf04U9dMgjLND84j9Vp3IfVXmusSUZ57Iw3UGvCrQBy 9c6NBIREwZ6GYsmNc9tu3mTqZgDjpSmlp/+UQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=eitanadler.com; s=0xdeadbeef; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=M3R1r5010NO8iMMn9IsaXOuFWBhprB+l+oOsAryGZ1buKI4kslVFNFaOwy0qlmbrYy paBhDybs86Jiv8WbfCN19MW4ndBqbfakilfqzM7enl0KiBkjnbZ4j5X3afXuTzFW8tvs qk8CEGNAEWXC7G6uS2WY+/KW6Z0DRILdXcxDw= Received: by 10.227.195.76 with SMTP id eb12mr4693554wbb.160.1301385607135; Tue, 29 Mar 2011 01:00:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.153.197 with HTTP; Tue, 29 Mar 2011 00:59:47 -0700 (PDT) In-Reply-To: <4D918988.8090802@gmail.com> References: <4D918988.8090802@gmail.com> From: Eitan Adler Date: Tue, 29 Mar 2011 02:59:47 -0500 Message-ID: To: David Demelier Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: freebsd-questions@freebsd.org Subject: Re: printf() leak? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Mar 2011 08:00:09 -0000 Hi David, > It seems printf() always alloc something and does not free it: What compiler and what optimizations? Most compilers will optimize a printf without any special formatting into a puts call instead of a printf call. For example clang -O3 -fomit-frame-pointer (which I use for clarity here) outputs this code: .file "leak.c" ... main: # @main # BB#0: # %entry subl $12, %esp movl $str, (%esp) calll puts xorl %eax, %eax addl $12, %esp ret .Ltmp0: ... str: .asciz "Hi" .size str, 3 ... [snip] > =3D=3D67840=3D=3D =C2=A0 =C2=A0 =C2=A0 =C2=A0 suppressed: 4,096 bytes in = 1 blocks Lets take a look at what valgrind says immediately after this: =3D=3D14481=3D=3D For counts of detected and suppressed errors, rerun with:= -v One of the lines we get is --14508-- used_suppression: 1 libc puts leak Which means it is a known issue and has been specially marked as to avoid being reported by valgrind. Lets take a look to see where this suppression happens: in /usr/local/lib/valgrind/default.supp we find { libc puts leak Memcheck:Leak fun:malloc obj:/lib/libc.so.7 obj:/lib/libc.so.7 obj:/lib/libc.so.7 fun:puts fun:main } After some investigation I was able to find the following commit: http://p4db.freebsd.org/chv.cgi?CH=3D168767 which shows when this suppression was added and by whom. I trust that if you are interested in the details of why this leak is detected you have the skills to follow up on this by yourself :-) Thank you for trying to make FreeBSD better! --=20 Eitan Adler