public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: newlib@sourceware.org
Subject: Re: [PATCH] newlib: Fix memory leak regarding gdtoa-based _ldtoa_r().
Date: Wed, 2 Aug 2023 15:39:04 +0900	[thread overview]
Message-ID: <20230802153904.297a5e45cd91334e2c106e41@nifty.ne.jp> (raw)
In-Reply-To: <ZMj8KuzFuJhb6xHd@calimero.vinschen.de>

On Tue, 1 Aug 2023 14:35:54 +0200
Corinna Vinschen wrote:
> Hi Takashi,
> 
> On Aug  1 17:57, Takashi Yano wrote:
> > After the commit a4705d387f78, printf() for floating-point values
> > causes a memory leak. The legacy _ldtoa_r() assumed the char pointer
> > returned will be free'ed by Bfree(). However, gdtoa-based _ldtoa_r()
> > returns the pointer returned by gdtoa() which should be free'ed by
> > freedtoa(). Due to this issue, the caller of _ldtoa_r() fails to free
> > the allocated char buffer. This is the cause of the said memory leak.
> > https://cygwin.com/pipermail/cygwin/2023-July/254054.html
> > 
> > With this patch, a new buffer is allocated using Balloc() and the
> > buffer returned by gdtoa() is copied into it. Then, free the original
> > buffer using freedtoa().
> 
> Basically this is ok. But the question is this.  Isn't it possible
> to redefine the allocator in gdtoa so that it uses a Balloced buffer
> right away?  Forinstance, by using overloading macros?  That would
> allow to get away without having to copy stuff...

Thanks for the advice. I tried that. Please check v2 patch.

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

      reply	other threads:[~2023-08-02  6:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-01  8:57 Takashi Yano
2023-08-01 12:35 ` Corinna Vinschen
2023-08-02  6:39   ` Takashi Yano [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=20230802153904.297a5e45cd91334e2c106e41@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=newlib@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).