Bug or not? printf allocates buffer & never frees it

Ian Pilcher arequipeno@gmail.com
Wed Mar 17 17:30:19 GMT 2021


Fedora 33 with glibc-2.32-4.fc33.x86_64.

Simple reproducer:

  #include <mcheck.h>
  #include <stdio.h>

  int main(void)
  {
	mtrace();
	printf("%d\n", 0);
	muntrace();
	return 0;
  }

Running with MALLOC_TRACE set shows:

  Memory not freed:
  -----------------
             Address     Size     Caller
  0x0000000000e1d690    0x400  at 0x7f19511d2934

The trace file shows that the memory was allocated by
_IO_file_doallocate:

  = Start
  @ /lib64/libc.so.6:(_IO_file_doallocate+0x94)[0x7f19511d2934] + 
0xe1d690 0x400
  = End

And gdb shows that _IO_file_doallocate is called from printf:

  #0  0x00007ffff7e578a0 in _IO_file_doallocate () from /lib64/libc.so.6
  #1  0x00007ffff7e662f0 in _IO_doallocbuf () from /lib64/libc.so.6
  #2  0x00007ffff7e65488 in __GI__IO_file_overflow () from /lib64/libc.so.6
  #3  0x00007ffff7e64536 in __GI__IO_file_xsputn () from /lib64/libc.so.6
  #4  0x00007ffff7e4f269 in __vfprintf_internal () from /lib64/libc.so.6
  #5  0x00007ffff7e3b2af in printf () from /lib64/libc.so.6
  #6  0x0000000000401163 in main () at leak.c:11

Multiple calls to printf don't leak additional memory, so this isn't
really a problem (other than the time wasted by folks hunting memory
leaks).

Is this considered a bug?

-- 
========================================================================
                  In Soviet Russia, Google searches you!
========================================================================



More information about the Libc-help mailing list