From: Jeff King <peff@peff.net>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Jeff Hostetler <git@jeffhostetler.com>,
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 1/1] mingw: safe-guard a bit more against getenv() problems
Date: Thu, 21 Feb 2019 08:58:05 -0500 [thread overview]
Message-ID: <20190221135805.GB20899@sigill.intra.peff.net> (raw)
In-Reply-To: <nycvar.QRO.7.76.6.1902181950130.45@tvgsbejvaqbjf.bet>
On Mon, Feb 18, 2019 at 07:57:14PM +0100, Johannes Schindelin wrote:
> > Why not use a mem_pool for this? We have that code isolated
> > and re-usable now. Have mingw_getenv() copy the string into
> > the pool always return the pointer from within the pool. The
> > pool automatically handles allocating new blocks as necessary.
> > And (if we care) we can bulk free the pool before existing.
>
> The problem with the mem_pool would be that I do *not* want to accumulate
> tons and tons of stale copies (remember that `difftool` bug? Apparently it
> calls `getenv()` in a loop that scales with the number of modified files;
> I would hate to have copies for all of those).
>
> And all you could do to remedy this would be to blow away all of them it
> the mem_pool grew too much, *including* the latest `getenv()` (which we
> painfully keep valid, e.g. in the case of `git_committer_info()` which
> calls `getenv()` *three* times *inside* the parameter list of the
> `fmt_ident()` function call.
One suggestion I made elsewhere[1] is to use strintern() to de-dup the
responses, and then keep them around forever. That bounds the memory
usage by the number of unique environment variables requested (which is
probably finite and limited), rather than the number of getenv() calls
(which as we have seen can be done in an arbitrary-sized loop).
I say "probably" because it's possible that there is code which mutates
the environment, reads it back, etc, in a loop. But that would be pretty
out-of-character for Git, I think.
-Peff
[1] https://public-inbox.org/git/20190115194726.GA5818@sigill.intra.peff.net/
next prev parent reply other threads:[~2019-02-21 13:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-15 15:17 [PATCH 0/1] Safe-guard the Windows code a bit more against getenv() problems Johannes Schindelin via GitGitGadget
2019-02-15 15:17 ` [PATCH 1/1] mingw: safe-guard " Johannes Schindelin via GitGitGadget
2019-02-15 16:14 ` Jeff Hostetler
2019-02-15 18:25 ` Junio C Hamano
2019-02-18 18:57 ` Johannes Schindelin
2019-02-21 13:58 ` Jeff King [this message]
2019-02-21 13:52 ` Jeff King
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190221135805.GB20899@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@jeffhostetler.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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).