[PATCH] mtrace: Use a static buffer for printing [BZ #25947]

DJ Delorie dj@redhat.com
Wed Aug 11 16:55:36 GMT 2021


Siddhesh Poyarekar via Libc-alpha <libc-alpha@sourceware.org> writes:
> -#define TRACE_BUFFER_SIZE 512

I think it would be prudent to keep this, instead of hard-coding the 512
in the code below.  I don't feel strongly about it, since the 512 only
appears once.

> -static char *malloc_trace_buffer;

We could have kept this here, too, but I have no real preference about
it.

> -      char *mtb = malloc (TRACE_BUFFER_SIZE);
> -      if (mtb == NULL)
> -        return;

Ok.

>            /* 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));

_IOFBF is same as before, so OK, but I wonder if _IOLBF (line buffered)
would be more user-friendly?  I can't think of a use case for piping the
output through "tail -f" or something, and actually needing to wait for
it, but it's text output.

> -      else
> -        free (mtb);

Ok.

LGTM as-is, my comments are for pondering only ;-)

Reviewed-by: DJ Delorie <dj@redhat.com>



More information about the Libc-alpha mailing list