From nobody Sun Dec 5 13:25:18 2021 X-Original-To: bugs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id E72DF1892913 for ; Sun, 5 Dec 2021 13:25:18 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4J6S3f4dScz3Jr8 for ; Sun, 5 Dec 2021 13:25:18 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 70F51187FF for ; Sun, 5 Dec 2021 13:25:18 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 1B5DPIKu068825 for ; Sun, 5 Dec 2021 13:25:18 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 1B5DPIC6068824 for bugs@FreeBSD.org; Sun, 5 Dec 2021 13:25:18 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 259294] [libc] add a freeres function Date: Sun, 05 Dec 2021 13:25:18 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: Unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: pjfloyd@wanadoo.fr X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@freebsd.org MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638710718; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i79idXDX1MLMd2eF0o2yfAOeArMG8DIV4qm3JgICorw=; b=dfsJRkL7MpWovU+SuoHGGl2rpzplPpTkwKkBHtI31GQp7LLbClHjMR1zsvzBA7bMSZbnTB rCR3xJCy/vjn/i3ERQ2urIZ6FOjSmXgp8gI5UmDff1ys0fXdv6u1PASKaaOf5Kr8CheVMt azxC+v9V4wAb/B9l0q85gBUDncf7uZo7FlLr0+dnHgwPNVPC6DDpDwbHzlGuOTTCjMBdvt 3vdnxpb5pPCoUYgN0oyvIKLg6CNj4bGzFrJj5TxD9yq4XqgvYcGm/N6o7V1B/3kUBkkDnI FjTy24s+HXO6vbGGwf+jhAsjexuor72s7EXH0OC/0dGCgynQU3dVPPWVgVGAEw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638710718; a=rsa-sha256; cv=none; b=VOOIWvZif6otU76eaCh2naZuMv1AM8yewAasP0BCFSniXY8M2XXL6klpEungJNNqAibiXQ k/OTD4GYk6sN1ALIvIbv9h6Nn14ZIWe5Uxx3XJQPMg/C6vyBBuYHxVpwF3+Qz9sMVr+2x3 EfreR6Aj+Mp2MTr8x7uatGgWlol2swgE26XZK19nuSJdl3A2GZO8g7cfA8Al5XoonCuCsR KFph/FxXpPF7Wh2u6OJxmt0AawUn/+LBWW2p+tDgumcmFOxpGn20daZMTmWP8FSYENk2R+ QrmK4ubKvEqRcYf/a017tsrYx3ryunZ79KWjKz3YwVIrrynEmp5S6zm4+M4huA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D259294 --- Comment #2 from Paul Floyd --- 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.=