]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
mtrace: Use a static buffer for printing [BZ #25947]
authorSiddhesh Poyarekar <siddhesh@sourceware.org>
Thu, 12 Aug 2021 01:08:15 +0000 (06:38 +0530)
committerSiddhesh Poyarekar <siddhesh@sourceware.org>
Thu, 12 Aug 2021 01:08:15 +0000 (06:38 +0530)
Use a static buffer for mtrace printing now that it no longer adds to
default libc footprint.

Reviewed-by: DJ Delorie <dj@redhat.com>
malloc/mtrace-impl.c

index 0e10ab7f604cda4851ae686249df9d2b1f5ecfc4..83008ca18fc707b42c5c6ad0f8d7bc8b5563abe2 100644 (file)
 
 #include <kernel-features.h>
 
-#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);
     }
 }