https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=282576

Dag-Erling Smørgrav <d...@freebsd.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |d...@freebsd.org

--- Comment #3 from Dag-Erling Smørgrav <d...@freebsd.org> ---
The “leak” isn't even in sysctlbyname(), which never allocates memory; it's in
printf().  You get the exact same result from this program:

    int main(void) { printf("Hello, world!\n"); }

Simply put, by default, the first time you try to print to stdout, libc will
allocate a 4 kB buffer which is never freed.  Adding the following line at the
top of your program renders stdout unbuffered and prevents the “leak”:

    setbuf(stdout, NULL);

Valgrind incorrectly reports the allocation as having occurred in vfprintf_l().
 It actually takes place in __smakebuf().  I suspect valgrind gets confused
because large parts of stdio are implemented as macros and inline functions for
performance reasons.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to