Date: Sun, 05 Dec 2021 13:25:18 +0000 From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 259294] [libc] add a freeres function Message-ID: <bug-259294-227-cIxiUFPtge@https.bugs.freebsd.org/bugzilla/> In-Reply-To: <bug-259294-227@https.bugs.freebsd.org/bugzilla/> References: <bug-259294-227@https.bugs.freebsd.org/bugzilla/>
next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D259294 --- Comment #2 from Paul Floyd <pjfloyd@wanadoo.fr> --- With a debug build of libc, if I run a canonical C 'printf hello world' as follows LD_PRELOAD=3D/home/paulf/build/src/obj/usr/home/paulf/build/src/amd64.amd64= /lib/libc/libc.so.7.full /home/paulf/scratch/valgrind/vg-in-place --default-suppressions=3Dno --leak-check=3Dyes --show-reachable=3Dyes ./hello_world then it tells me that the still reachable memory is =3D=3D89763=3D=3D 4,096 bytes in 1 blocks are still reachable in loss recor= d 1 of 1 =3D=3D89763=3D=3D at 0x484C894: malloc (vg_replace_malloc.c:385) =3D=3D89763=3D=3D by 0x49716D2: __smakebuf (lib/libc/stdio/makebuf.c:73) =3D=3D89763=3D=3D by 0x4984164: __swsetup (lib/libc/stdio/wsetup.c:82) =3D=3D89763=3D=3D by 0x4977D82: __vfprintf (lib/libc/stdio/vfprintf.c:46= 2) =3D=3D89763=3D=3D by 0x4977AF9: vfprintf_l (lib/libc/stdio/vfprintf.c:28= 5) =3D=3D89763=3D=3D by 0x4972703: printf (lib/libc/stdio/printf.c:57) =3D=3D89763=3D=3D by 0x2018A8: main (hello_world.c:5) Looking at the source, calls to printf pass through #define prepwrite(fp) \ ((((fp)->_flags & __SWR) =3D=3D 0 || \ ((fp)->_bf._base =3D=3D NULL && ((fp)->_flags & __SSTR) =3D=3D = 0)) && \ __swsetup(fp) This checks that the buffer associated with stdout (also applies to stderr)= is allocated and if not allocates it. I'll add a patch in a moment that seems to work, at least for stdout (should work for stderr, not tested) paulf> LD_PRELOAD=3D/home/paulf/build/src/obj/usr/home/paulf/build/src/amd64.amd64= /lib/libc/libc.so.7.full /home/paulf/scratch/valgrind/vg-in-place --default-suppressions=3Dno --leak-check=3Dyes --show-reachable=3Dyes ./hello_world =3D=3D69502=3D=3D Memcheck, a memory error detector =3D=3D69502=3D=3D Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward = et al. =3D=3D69502=3D=3D Using Valgrind-3.19.0.GIT and LibVEX; rerun with -h for c= opyright info =3D=3D69502=3D=3D Command: ./hello_world =3D=3D69502=3D=3D=20 Hellw, World! =3D=3D69502=3D=3D=20 =3D=3D69502=3D=3D HEAP SUMMARY: =3D=3D69502=3D=3D in use at exit: 0 bytes in 0 blocks =3D=3D69502=3D=3D total heap usage: 1 allocs, 1 frees, 4,096 bytes alloca= ted =3D=3D69502=3D=3D=20 =3D=3D69502=3D=3D All heap blocks were freed -- no leaks are possible =3D=3D69502=3D=3D=20 =3D=3D69502=3D=3D For lists of detected and suppressed errors, rerun with: = -s =3D=3D69502=3D=3D ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 fr= om 0) --=20 You are receiving this mail because: You are the assignee for the bug.=
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-259294-227-cIxiUFPtge>