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

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



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