From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org, Dmitry Potapov <dpotapov@gmail.com>
Subject: Re: [PATCH] hash-object: fix a trivial leak in --path
Date: Sun, 06 Feb 2022 17:57:23 -0800 [thread overview]
Message-ID: <xmqq4k5bigl8.fsf@gitster.g> (raw)
In-Reply-To: <patch-1.1-53863df1455-20220205T000422Z-avarab@gmail.com> ("Ævar Arnfjörð Bjarmason"'s message of "Sat, 5 Feb 2022 01:04:29 +0100")
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> diff --git a/builtin/hash-object.c b/builtin/hash-object.c
> index c7b3ad74c60..db9b2535271 100644
> --- a/builtin/hash-object.c
> +++ b/builtin/hash-object.c
> @@ -92,6 +92,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
> int nongit = 0;
> unsigned flags = HASH_FORMAT_CHECK;
> const char *vpath = NULL;
> + char *vpath_free = NULL;
> const struct option hash_object_options[] = {
> OPT_STRING('t', NULL, &type, N_("type"), N_("object type")),
> OPT_BIT('w', NULL, &flags, N_("write the object into the object database"),
> @@ -114,8 +115,10 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
> else
> prefix = setup_git_directory_gently(&nongit);
>
> - if (vpath && prefix)
> - vpath = prefix_filename(prefix, vpath);
> + if (vpath && prefix) {
> + vpath_free = prefix_filename(prefix, vpath);
> + vpath = vpath_free;
> + }
>
> git_config(git_default_config, NULL);
>
> @@ -156,5 +159,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
> if (stdin_paths)
> hash_stdin_paths(type, no_filters, flags, literally);
>
> + free(vpath_free);
> +
Heh.
This is not wrong per-se, but we are about to exit and clean-up, so
having leak-checker complain about this and having us spend brain
cycles to worry about it is a sad thing.
Will queue. Thanks.
> return 0;
> }
> diff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh
> index 64b340f2272..ac5ad8c7402 100755
> --- a/t/t1007-hash-object.sh
> +++ b/t/t1007-hash-object.sh
> @@ -2,6 +2,7 @@
>
> test_description="git hash-object"
>
> +TEST_PASSES_SANITIZE_LEAK=true
> . ./test-lib.sh
>
> echo_without_newline() {
prev parent reply other threads:[~2022-02-07 1:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-05 0:04 [PATCH] hash-object: fix a trivial leak in --path Ævar Arnfjörð Bjarmason
2022-02-07 1:57 ` Junio C Hamano [this message]
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=xmqq4k5bigl8.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=avarab@gmail.com \
--cc=dpotapov@gmail.com \
--cc=git@vger.kernel.org \
/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.