git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Martin Ågren" <martin.agren@gmail.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 2/2] diff.[ch]: have diff_free() free options->parseopts
Date: Wed, 16 Feb 2022 11:56:29 +0100	[thread overview]
Message-ID: <patch-2.2-7f320062419-20220216T105250Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-0.2-00000000000-20220216T105250Z-avarab@gmail.com>

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


  parent reply	other threads:[~2022-02-16 10:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-16 10:56 [PATCH 0/2] diff_free(): free a bit more, fix leaks Ævar Arnfjörð Bjarmason
2022-02-16 10:56 ` [PATCH 1/2] diff.[ch]: have diff_free() call clear_pathspec(opts.pathspec) Ævar Arnfjörð Bjarmason
2022-02-16 16:50   ` Elijah Newren
2022-02-17 10:22     ` Ævar Arnfjörð Bjarmason
2022-02-16 21:48   ` Junio C Hamano
2022-02-16 10:56 ` Ævar Arnfjörð Bjarmason [this message]
2022-02-16 16:51   ` [PATCH 2/2] diff.[ch]: have diff_free() free options->parseopts Elijah Newren
2022-02-16 16:52 ` [PATCH 0/2] diff_free(): free a bit more, fix leaks Elijah Newren

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=patch-2.2-7f320062419-20220216T105250Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=martin.agren@gmail.com \
    --cc=pclouds@gmail.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).