From owner-freebsd-questions@FreeBSD.ORG Tue Mar 29 08:08:37 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 0A3821065670 for ; Tue, 29 Mar 2011 08:08:37 +0000 (UTC) (envelope-from demelier.david@gmail.com) Received: from mail-fx0-f54.google.com (mail-fx0-f54.google.com [209.85.161.54]) by mx1.freebsd.org (Postfix) with ESMTP id 898288FC1D for ; Tue, 29 Mar 2011 08:08:36 +0000 (UTC) Received: by fxm11 with SMTP id 11so4242868fxm.13 for ; Tue, 29 Mar 2011 01:08:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=6Z8ZdaISI3+43UaJNC+S73mu8SZHMnW5eZx3xwTRyqs=; b=gFiB9F8NsOSu2eSrrF9RAkvIUFnrLYqHzoNVTBYx1zNfKof5KAKkixcoHdxdFtVoTb tbQy7Oqpo6ue+P6kmg/g35xZD6Myetm9nJsRtyU967ngKOnfkPQI9lKIdfSivFiV4woF N0uaQuqPvcoyuK1F8ZNLQcVVDX5m7gDCOmF9Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=x8u2PDvJbaj7dQmp5d2rt4dg2oTBgOvmkJPpcg6oVrZbfjmIO9YsskzkAzpEKAzC5h orUVo3tDD8d5bm8S0QwffSovaIGRUdP6YF+WQE95U2W6n08rdhg8H34lXe3i12d9vDyB Xb+EN0YU2/UEq1slBpCz8EZtUsvhOi5qmlvos= Received: by 10.223.160.80 with SMTP id m16mr5592484fax.72.1301386115436; Tue, 29 Mar 2011 01:08:35 -0700 (PDT) Received: from Melon.malikania.fr (wifi-osiris-sec-183-249.u-strasbg.fr [130.79.183.249]) by mx.google.com with ESMTPS id b18sm1820758fak.32.2011.03.29.01.08.33 (version=SSLv3 cipher=OTHER); Tue, 29 Mar 2011 01:08:34 -0700 (PDT) Message-ID: <4D919381.70109@gmail.com> Date: Tue, 29 Mar 2011 10:08:33 +0200 From: David Demelier User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.2.15) Gecko/20110306 Thunderbird/3.1.9 MIME-Version: 1.0 To: Eitan Adler References: <4D918988.8090802@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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:08:37 -0000 On 29/03/2011 09:59, Eitan Adler wrote: > 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. I was using clang / gcc without any optimisations. > 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] >> ==67840== suppressed: 4,096 bytes in 1 blocks > > Lets take a look at what valgrind says immediately after this: > ==14481== For counts of detected and suppressed errors, rerun with: -v > > One of the lines we get is > --14508-- used_suppression: 1 libc puts leak > I didn't see this one, thanks! > 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=168767 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 :-) > Thanks a lot for the details. > Thank you for trying to make FreeBSD better! > > :-) -- David Demelier