From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/2] format-patch: free elements of rev.ref_message_ids list
Date: Thu, 18 May 2023 18:32:14 -0700 [thread overview]
Message-ID: <xmqqttw9qf6p.fsf@gitster.g> (raw)
In-Reply-To: <20230519000543.GB1975194@coredump.intra.peff.net> (Jeff King's message of "Thu, 18 May 2023 20:05:43 -0400")
Jeff King <peff@peff.net> writes:
> When we are showing multiple patches with format-patch, we have to
> repeatedly overwrite the rev.message_id field. We take care to avoid
> leaking the old value by either freeing it, or adding it to
> ref_message_ids, a string list of ids to reference in subsequent
> messages.
>
> But unfortunately we do leak the value via that string list. We try
> to clear the string list, courtesy of 89f45cf4eb (format-patch: don't
> leak "extra_headers" or "ref_message_ids", 2022-04-13). But since it was
> initialized as "nodup", the string list doesn't realize it owns the
> strings, and it leaks them.
>
> We have two options here:
>
> 1. Continue to init with "nodup", but then tweak the value of
> ref_message_ids.strdup_strings just before clearing.
>
> 2. Init with "dup", but use "append_nodup" when transferring ownership
> of strings to the list. Clearing just works.
>
> I picked the second here, as I think it calls attention to the tricky
> part (transferring ownership via the nodup call).
This is pretty much what I had in mind wheh I wrote the log message
for the follow-up "Yikes, for now let's mark the test no longer
sanitizer clean" patch. Very pleased to see a clean-up I punted
materialize while I was looking the other way ;-)
> There's one other related fix we have to do, though. We also insert the
> result of clean_message_id() into the list. This _sometimes_ allocates
> and sometimes does not, depending on whether we have to remove cruft
> from the end of the string. Let's teach it to consistently return an
> allocated string, so that the caller knows it must be freed.
Yes!
Thanks.
next prev parent reply other threads:[~2023-05-19 1:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-19 0:02 [PATCH 0/2] a few format-patch leak fixes Jeff King
2023-05-19 0:03 ` [PATCH 1/2] format-patch: free rev.message_id when exiting Jeff King
2023-05-19 0:05 ` [PATCH 2/2] format-patch: free elements of rev.ref_message_ids list Jeff King
2023-05-19 1:32 ` Junio C Hamano [this message]
2023-05-19 14:54 ` Konstantin Khomoutov
2023-05-19 16:56 ` Junio C Hamano
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=xmqqttw9qf6p.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.