From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7814) id BE3033951863; Mon, 16 Aug 2021 17:14:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE3033951863 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Fangrui Song To: glibc-cvs@sourceware.org Subject: [glibc/maskray/lld] mtrace: Use a static buffer for printing [BZ #25947] X-Act-Checkin: glibc X-Git-Author: Siddhesh Poyarekar X-Git-Refname: refs/heads/maskray/lld X-Git-Oldrev: 5a5358b749d0b153de6f6361342d06228d7270be X-Git-Newrev: dc906e94f7033892dadbd91718349f19e1376391 Message-Id: <20210816171459.BE3033951863@sourceware.org> Date: Mon, 16 Aug 2021 17:14:59 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Aug 2021 17:14:59 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=dc906e94f7033892dadbd91718349f19e1376391 commit dc906e94f7033892dadbd91718349f19e1376391 Author: Siddhesh Poyarekar Date: Thu Aug 12 06:38:15 2021 +0530 mtrace: Use a static buffer for printing [BZ #25947] Use a static buffer for mtrace printing now that it no longer adds to default libc footprint. Reviewed-by: DJ Delorie Diff: --- malloc/mtrace-impl.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/malloc/mtrace-impl.c b/malloc/mtrace-impl.c index 0e10ab7f60..83008ca18f 100644 --- a/malloc/mtrace-impl.c +++ b/malloc/mtrace-impl.c @@ -34,11 +34,8 @@ #include -#define TRACE_BUFFER_SIZE 512 - static FILE *mallstream; static const char mallenv[] = "MALLOC_TRACE"; -static char *malloc_trace_buffer; static void tr_where (const void *caller, Dl_info *info) @@ -184,16 +181,13 @@ do_mtrace (void) mallfile = secure_getenv (mallenv); if (mallfile != NULL) { - char *mtb = malloc (TRACE_BUFFER_SIZE); - if (mtb == NULL) - return; - mallstream = fopen (mallfile != NULL ? mallfile : "/dev/null", "wce"); if (mallstream != NULL) { /* Be sure it doesn't malloc its buffer! */ - malloc_trace_buffer = mtb; - setvbuf (mallstream, malloc_trace_buffer, _IOFBF, TRACE_BUFFER_SIZE); + static char tracebuf [512]; + + setvbuf (mallstream, tracebuf, _IOFBF, sizeof (tracebuf)); fprintf (mallstream, "= Start\n"); if (!added_atexit_handler) { @@ -203,8 +197,6 @@ do_mtrace (void) } __malloc_debug_enable (MALLOC_MTRACE_HOOK); } - else - free (mtb); } }