git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 10/23] builtin/pull: fix leaking "ff" option
Date: Tue, 24 Sep 2024 09:20:19 +0200	[thread overview]
Message-ID: <ZvJoM_JbJKPrgHnC@pks.im> (raw)
In-Reply-To: <xmqq4j6a45wr.fsf@gitster.g>

On Fri, Sep 20, 2024 at 10:00:04AM -0700, Junio C Hamano wrote:
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > The `opt_ff` field gets populated either via `OPT_PASSTHRU` via
> > `config_get_ff()` or when `--rebase` is passed. So we sometimes end up
> > overriding the value in `opt_ff` with another value, but we do not free
> > the old value, causing a memory leak.
> 
> Good eyes.
> 
> I have to wonder if it will come back and bite us again that
> OPT_PASSTHRU does not pass through but creates a new copy, while
> OPT_STRING borrows from the argv[].  I guess that we could check in
> parse_options_check() if the address of the same variable is passed
> to both OPT_PASSTHRU (giving it a piece of memory we are responsible
> for freeing) and OPT_STRING (giving it a piece of memory borrowed
> from argv[], and would trigger a failure if given to free()).
> 
> In an extremely longer run, I wonder if it becomes necessary for us
> to also make OPT_STRING to make a copy (which means strings that
> come from the configuration and from parsing the command line
> arguments are all allocated ones that we are responsible to free).

For now it seems like we are fine with `OPT_STRING` not copying the
value, and I haven't yet found a situation where we cannot work around
the alloc/don't alloc split. But it certainly does lead to an awkward
calling convention in many places that makes the resulting code way
harder to read than necessary if it did allocate.

I also doubt that avoiding an allocation for these gives us a noticeable
speedup. After all we're bounded by the number of arguments passed by
the user, so it's not like we would end up dupliciating thousands of
strings in the general case.

So yes, I think that it would simplify things quite a bit when all three
of them (OPT_PASSTHRU, OPT_STRING, config parsing) were duplicating the
values.

Patrick

  reply	other threads:[~2024-09-24  7:20 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-16 11:45 [PATCH 00/23] Memory leak fixes (pt.7) Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 01/23] builtin/help: fix dangling reference to `html_path` Patrick Steinhardt
2024-09-16 16:24   ` Justin Tobler
2024-09-16 11:45 ` [PATCH 02/23] builtin/help: fix leaking `html_path` when reading config multiple times Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 03/23] git: fix leaking argv when handling builtins Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 04/23] submodule: fix leaking update strategy Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 05/23] builtin/submodule--helper: clear child process when not running it Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 06/23] builtin/submodule--helper: fix leaking error buffer Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 07/23] t/helper: fix leaking subrepo in nested submodule config helper Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 08/23] builtin/submodule--helper: fix leaking remote ref on errors Patrick Steinhardt
2024-09-16 18:51   ` Justin Tobler
2024-09-17 10:19     ` Patrick Steinhardt
2024-09-25 20:26       ` Junio C Hamano
2024-09-26 11:58         ` Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 09/23] dir: fix off by one errors for ignored and untracked entries Patrick Steinhardt
2024-09-20 16:43   ` Junio C Hamano
2024-09-16 11:45 ` [PATCH 10/23] builtin/pull: fix leaking "ff" option Patrick Steinhardt
2024-09-20 17:00   ` Junio C Hamano
2024-09-24  7:20     ` Patrick Steinhardt [this message]
2024-09-16 11:45 ` [PATCH 11/23] diff: fix leaking orderfile option Patrick Steinhardt
2024-09-16 11:45 ` [PATCH 12/23] parse-options: free previous value of `OPTION_FILENAME` Patrick Steinhardt
2024-09-20 17:21   ` Junio C Hamano
2024-09-16 11:46 ` [PATCH 13/23] diffcore-order: fix leaking buffer when parsing orderfiles Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 14/23] builtin/repack: fix leaking configuration Patrick Steinhardt
2024-09-20 17:28   ` Junio C Hamano
2024-09-16 11:46 ` [PATCH 15/23] builtin/difftool: plug several trivial memory leaks Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 16/23] trace2: destroy context stored in thread-local storage Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 17/23] submodule: fix leaking submodule ODB paths Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 18/23] grep: fix leaking grep pattern Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 19/23] promisor-remote: fix leaking partial clone filter Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 20/23] builtin/maintenance: fix leaking config string Patrick Steinhardt
2024-09-20 17:59   ` Junio C Hamano
2024-09-16 11:46 ` [PATCH 21/23] builtin/maintenance: fix leak in `get_schedule_cmd()` Patrick Steinhardt
2024-09-16 11:46 ` [PATCH 22/23] revision: fix leaking parents when simplifying commits Patrick Steinhardt
2024-09-19 17:17   ` Junio C Hamano
2024-09-16 11:46 ` [PATCH 23/23] diffcore-break: fix leaking filespecs when merging broken pairs Patrick Steinhardt
2024-09-19 18:54 ` [PATCH 00/23] Memory leak fixes (pt.7) Junio C Hamano
2024-09-24  7:20   ` Patrick Steinhardt
2024-09-26 11:45 ` [PATCH v2 " Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 01/23] builtin/help: fix dangling reference to `html_path` Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 02/23] builtin/help: fix leaking `html_path` when reading config multiple times Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 03/23] git: fix leaking argv when handling builtins Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 04/23] submodule: fix leaking update strategy Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 05/23] builtin/submodule--helper: clear child process when not running it Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 06/23] builtin/submodule--helper: fix leaking error buffer Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 07/23] t/helper: fix leaking subrepo in nested submodule config helper Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 08/23] builtin/submodule--helper: fix leaking remote ref on errors Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 09/23] dir: fix off by one errors for ignored and untracked entries Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 10/23] builtin/pull: fix leaking "ff" option Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 11/23] diff: fix leaking orderfile option Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 12/23] parse-options: free previous value of `OPTION_FILENAME` Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 13/23] diffcore-order: fix leaking buffer when parsing orderfiles Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 14/23] builtin/repack: fix leaking configuration Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 15/23] builtin/difftool: plug several trivial memory leaks Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 16/23] trace2: destroy context stored in thread-local storage Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 17/23] submodule: fix leaking submodule ODB paths Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 18/23] grep: fix leaking grep pattern Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 19/23] promisor-remote: fix leaking partial clone filter Patrick Steinhardt
2024-09-26 11:46   ` [PATCH v2 20/23] builtin/maintenance: fix leaking config string Patrick Steinhardt
2024-09-26 11:47   ` [PATCH v2 21/23] builtin/maintenance: fix leak in `get_schedule_cmd()` Patrick Steinhardt
2024-09-26 11:47   ` [PATCH v2 22/23] revision: fix leaking parents when simplifying commits Patrick Steinhardt
2024-09-26 11:47   ` [PATCH v2 23/23] diffcore-break: fix leaking filespecs when merging broken pairs Patrick Steinhardt

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=ZvJoM_JbJKPrgHnC@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --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.
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 NNTP newsgroup(s).