git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] diff.[ch]: have diff_free() free options->parseopts

From
Elijah Newren <newren@gmail.com>
Date
Feb 16, 2022, 16:51 UTC
Message-ID
<CABPp-BEyTnfEANPii-33y0g3fQgkRY8Bz3zaXScN__Ad7z4n1g@mail.gmail.com>
In-Reply-To
<patch-2.2-7f320062419-20220216T105250Z-avarab@gmail.com>

On Wed, Feb 16, 2022 at 7:59 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

Show 44 quoted lines
>
> The "struct option" added in 4a288478394 (diff.c: prepare to use
> parse_options() for parsing, 2019-01-27) would be free'd in the case
> of diff_setup_done() being called.
>
> But not all codepaths that allocate it reach that,
> e.g. "t6427-diff3-conflict-markers.sh" will now free memory that it
> didn't free before. By using FREE_AND_NULL() here (which
> diff_setup_done() also does) we ensure that we free the memory, and
> that we won't have double-free's.
>
> Before this running:
>
>     ./t6427-diff3-conflict-markers.sh -vixd --run=7
>
> Would report:
>
>     SUMMARY: LeakSanitizer: 7823 byte(s) leaked in 6 allocation(s).
>
> But now we'll report:
>
>     SUMMARY: LeakSanitizer: 703 byte(s) leaked in 5 allocation(s).
>
> I.e. the largest leak in that particular test has now been addressed.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  diff.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/diff.c b/diff.c
> index 0aef3db6e10..fb8bc8aadbf 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -6346,6 +6346,7 @@ void diff_free(struct diff_options *options)
>         diff_free_file(options);
>         diff_free_ignore_regex(options);
>         clear_pathspec(&options->pathspec);
> +       FREE_AND_NULL(options->parseopts);
>  }
>
>  void diff_flush(struct diff_options *options)
> --
> 2.35.1.1028.g2d2d4be19de
Makes sense.
Previous: Ævar Arnfjörð BjarmasonNext: Elijah Newren
Message 7 of 8 in “diff_free(): free a bit more, fix leaks”
  1. 0/2 diff_free(): free a bit more, fix leaksÆvar Arnfjörð Bjarmason, Feb 16, 2022
  2. 1/2 diff.[ch]: have diff_free() call clear_pathspec(opts.pathspec)Ævar Arnfjörð Bjarmason, Feb 16, 2022
  3. Elijah NewrenFeb 16, 2022
  4. Ævar Arnfjörð BjarmasonFeb 17, 2022
  5. Junio C HamanoFeb 16, 2022
  6. 2/2 diff.[ch]: have diff_free() free options->parseoptsÆvar Arnfjörð Bjarmason, Feb 16, 2022
  7. Elijah NewrenFeb 16, 2022
  8. Elijah NewrenFeb 16, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.