public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Konstantin Kharlamov <hi-angel@yandex.ru>
To: Ian Pilcher <arequipeno@gmail.com>, libc-help@sourceware.org
Subject: Re: Bug or not? printf allocates buffer & never frees it
Date: Wed, 17 Mar 2021 22:23:14 +0300	[thread overview]
Message-ID: <1c2230b2d1f2ffef4ac8041188373ebbdc6064cc.camel@yandex.ru> (raw)
In-Reply-To: <s2tebb$135j$1@ciao.gmane.io>

On Wed, 2021-03-17 at 12:30 -0500, Ian Pilcher via Libc-help wrote:
> 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?
> 

Hi! I'm not very acknowledged with the output, am I right that printf calls "deallocate", however the actual memory is still being held and not returned to the kernel? If yes, then you're likely stumbled upon this bug https://sourceware.org/bugzilla/show_bug.cgi?id=27103 See also this gigantic thread https://debbugs.gnu.org/cgi/bugreport.cgi?bug=45200


      parent reply	other threads:[~2021-03-17 19:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17 17:30 Ian Pilcher
2021-03-17 17:45 ` Florian Weimer
2021-03-17 20:29   ` Ian Pilcher
2021-03-17 20:47   ` Godmar Back
2021-03-17 21:03     ` Florian Weimer
2021-03-17 19:23 ` Konstantin Kharlamov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1c2230b2d1f2ffef4ac8041188373ebbdc6064cc.camel@yandex.ru \
    --to=hi-angel@yandex.ru \
    --cc=arequipeno@gmail.com \
    --cc=libc-help@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).