Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 Mar 2011 10:08:33 +0200
From:      David Demelier <demelier.david@gmail.com>
To:        Eitan Adler <lists@eitanadler.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: printf() leak?
Message-ID:  <4D919381.70109@gmail.com>
In-Reply-To: <AANLkTikyzSj8Nypo1ZDJhs97k-YZ65qda18vkSDNhnFz@mail.gmail.com>
References:  <4D918988.8090802@gmail.com> <AANLkTikyzSj8Nypo1ZDJhs97k-YZ65qda18vkSDNhnFz@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4D919381.70109>