1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

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 <dj@redhat.com>
This commit is contained in:
Siddhesh Poyarekar
2021-08-12 06:38:15 +05:30
parent 5a5358b749
commit dc906e94f7

View File

@@ -34,11 +34,8 @@
#include <kernel-features.h> #include <kernel-features.h>
#define TRACE_BUFFER_SIZE 512
static FILE *mallstream; static FILE *mallstream;
static const char mallenv[] = "MALLOC_TRACE"; static const char mallenv[] = "MALLOC_TRACE";
static char *malloc_trace_buffer;
static void static void
tr_where (const void *caller, Dl_info *info) tr_where (const void *caller, Dl_info *info)
@@ -184,16 +181,13 @@ do_mtrace (void)
mallfile = secure_getenv (mallenv); mallfile = secure_getenv (mallenv);
if (mallfile != NULL) if (mallfile != NULL)
{ {
char *mtb = malloc (TRACE_BUFFER_SIZE);
if (mtb == NULL)
return;
mallstream = fopen (mallfile != NULL ? mallfile : "/dev/null", "wce"); mallstream = fopen (mallfile != NULL ? mallfile : "/dev/null", "wce");
if (mallstream != NULL) if (mallstream != NULL)
{ {
/* Be sure it doesn't malloc its buffer! */ /* Be sure it doesn't malloc its buffer! */
malloc_trace_buffer = mtb; static char tracebuf [512];
setvbuf (mallstream, malloc_trace_buffer, _IOFBF, TRACE_BUFFER_SIZE);
setvbuf (mallstream, tracebuf, _IOFBF, sizeof (tracebuf));
fprintf (mallstream, "= Start\n"); fprintf (mallstream, "= Start\n");
if (!added_atexit_handler) if (!added_atexit_handler)
{ {
@@ -203,8 +197,6 @@ do_mtrace (void)
} }
__malloc_debug_enable (MALLOC_MTRACE_HOOK); __malloc_debug_enable (MALLOC_MTRACE_HOOK);
} }
else
free (mtb);
} }
} }