[Bug 282576] Memory leak in sysctlbyname FreeBSD 14.1-RELEASE-p5 GENERIC x64
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 28 Feb 2025 16:32:58 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=282576
Dag-Erling Smørgrav <des@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |des@FreeBSD.org
--- Comment #3 from Dag-Erling Smørgrav <des@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.