printf() leak?

David Demelier demelier.david at gmail.com
Tue Mar 29 08:08:37 UTC 2011


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


More information about the freebsd-questions mailing list