git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Elijah Newren <newren@gmail.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: "Git Mailing List" <git@vger.kernel.org>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Martin Ågren" <martin.agren@gmail.com>,
	"Andrzej Hunt" <ajrhunt@google.com>, "Jeff King" <peff@peff.net>
Subject: Re: [PATCH 2/7] tests: fix a memory leak in test-parse-options.c
Date: Wed, 6 Oct 2021 09:37:46 -0700	[thread overview]
Message-ID: <CABPp-BFgsAKX1nxaX5Rk0XvOjsSxUveEXbqRgrm3n_ZG4Skd7g@mail.gmail.com> (raw)
In-Reply-To: <patch-2.7-c24e115aa49-20211006T095426Z-avarab@gmail.com>

On Wed, Oct 6, 2021 at 3:02 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
>
> Fix a memory leak in t/helper/test-parse-options.c, we were not
> freeing the allocated "struct string_list" or its items. While I'm at
> it move the declaration of the "list" string_list the
> cmd__parse_options() function.

missing verb after the final "string_list"?  I'm having trouble
parsing this paragraph.

> In c8ba1639165 (parse-options: add OPT_STRING_LIST helper, 2011-06-09)
> the "list" variable was added, and later on in
> c8ba1639165 (parse-options: add OPT_STRING_LIST helper, 2011-06-09)
> the "expect" was added.
>
> The "list" variable was last touched in 2721ce21e43 (use string_list
> initializer consistently, 2016-06-13), but it was still left at the
> static scope, it's better to move it to the function for consistency.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  t/helper/test-parse-options.c | 7 ++++++-
>  t/t0040-parse-options.sh      | 1 +
>  2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c
> index a282b6ff13e..48d3cf6692d 100644
> --- a/t/helper/test-parse-options.c
> +++ b/t/helper/test-parse-options.c
> @@ -14,7 +14,6 @@ static int dry_run = 0, quiet = 0;
>  static char *string = NULL;
>  static char *file = NULL;
>  static int ambiguous;
> -static struct string_list list = STRING_LIST_INIT_NODUP;
>
>  static struct {
>         int called;
> @@ -107,6 +106,8 @@ int cmd__parse_options(int argc, const char **argv)
>                 NULL
>         };
>         struct string_list expect = STRING_LIST_INIT_NODUP;
> +       struct string_list list = STRING_LIST_INIT_NODUP;
> +
>         struct option options[] = {
>                 OPT_BOOL(0, "yes", &boolean, "get a boolean"),
>                 OPT_BOOL('D', "no-doubt", &boolean, "begins with 'no-'"),
> @@ -185,5 +186,9 @@ int cmd__parse_options(int argc, const char **argv)
>         for (i = 0; i < argc; i++)
>                 show(&expect, &ret, "arg %02d: %s", i, argv[i]);
>
> +       expect.strdup_strings = 1;
> +       string_list_clear(&expect, 0);
> +       string_list_clear(&list, 0);
> +
>         return ret;
>  }
> diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
> index da310ed29b1..ed422a1a616 100755
> --- a/t/t0040-parse-options.sh
> +++ b/t/t0040-parse-options.sh
> @@ -5,6 +5,7 @@
>
>  test_description='our own option parser'
>
> +TEST_PASSES_SANITIZE_LEAK=true
>  . ./test-lib.sh
>
>  cat >expect <<\EOF
> --
> 2.33.0.1441.gbbcdb4c3c66

Otherwise, looks good.

  reply	other threads:[~2021-10-06 16:38 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-06 10:02 [PATCH 0/7] leak tests: fix "test-tool" & other small leaks Ævar Arnfjörð Bjarmason
2021-10-06 10:02 ` [PATCH 1/7] tests: fix a memory leak in test-prio-queue.c Ævar Arnfjörð Bjarmason
2021-10-06 10:02 ` [PATCH 2/7] tests: fix a memory leak in test-parse-options.c Ævar Arnfjörð Bjarmason
2021-10-06 16:37   ` Elijah Newren [this message]
2021-10-06 10:02 ` [PATCH 3/7] tests: fix a memory leak in test-oidtree.c Ævar Arnfjörð Bjarmason
2021-10-06 10:02 ` [PATCH 4/7] tests: fix test-oid-array leak, test in SANITIZE=leak Ævar Arnfjörð Bjarmason
2021-10-06 10:02 ` [PATCH 5/7] ls-files: fix a trivial dir_clear() leak Ævar Arnfjörð Bjarmason
2021-10-06 10:02 ` [PATCH 6/7] ls-files: add missing string_list_clear() Ævar Arnfjörð Bjarmason
2021-10-06 10:02 ` [PATCH 7/7] merge: add missing strbuf_release() Ævar Arnfjörð Bjarmason
2021-10-06 16:47 ` [PATCH 0/7] leak tests: fix "test-tool" & other small leaks Elijah Newren
2021-10-07 10:01 ` [PATCH v2 " Ævar Arnfjörð Bjarmason
2021-10-07 10:01   ` [PATCH v2 1/7] tests: fix a memory leak in test-prio-queue.c Ævar Arnfjörð Bjarmason
2021-10-07 10:01   ` [PATCH v2 2/7] tests: fix a memory leak in test-parse-options.c Ævar Arnfjörð Bjarmason
2021-10-07 10:01   ` [PATCH v2 3/7] tests: fix a memory leak in test-oidtree.c Ævar Arnfjörð Bjarmason
2021-10-07 10:01   ` [PATCH v2 4/7] tests: fix test-oid-array leak, test in SANITIZE=leak Ævar Arnfjörð Bjarmason
2021-10-07 10:01   ` [PATCH v2 5/7] ls-files: fix a trivial dir_clear() leak Ævar Arnfjörð Bjarmason
2021-10-07 22:46     ` Junio C Hamano
2021-10-13 13:39       ` Ævar Arnfjörð Bjarmason
2021-10-13 19:01         ` Junio C Hamano
2021-10-14  0:15           ` Ævar Arnfjörð Bjarmason
2021-10-14 17:38             ` Junio C Hamano
2021-10-07 10:01   ` [PATCH v2 6/7] ls-files: add missing string_list_clear() Ævar Arnfjörð Bjarmason
2021-10-07 10:01   ` [PATCH v2 7/7] merge: add missing strbuf_release() Ævar Arnfjörð Bjarmason

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=CABPp-BFgsAKX1nxaX5Rk0XvOjsSxUveEXbqRgrm3n_ZG4Skd7g@mail.gmail.com \
    --to=newren@gmail.com \
    --cc=ajrhunt@google.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=martin.agren@gmail.com \
    --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.
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).