From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: peff@peff.net
Subject: [PATCH] hash-object: prefix_filename() returns allocated memory these days
Date: Tue, 07 Sep 2021 15:10:22 -0700 [thread overview]
Message-ID: <xmqqsfyg82b5.fsf@gitster.g> (raw)
Back when a1be47e4 (hash-object: fix buffer reuse with --path in a
subdirectory, 2017-03-20) was written, the prefix_filename() helper
used a static piece of memory to the caller, making the caller
responsible for copying it, if it wants to keep it across another
call to the same function. Two callers of the prefix_filename() in
hash-object were made to xstrdup() the value obtained from it.
But in the same series, when e4da43b1 (prefix_filename: return newly
allocated string, 2017-03-20) changed the rule to gave the caller
possession of the memory, we forgot to revert one of the xstrdup()
changes, allowing the returned value to leak.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
* "git show -W e4da43b1 builtin/hash-object.c" made me curious.
builtin/hash-object.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git c/builtin/hash-object.c w/builtin/hash-object.c
index 640ef4ded5..084cba204b 100644
--- c/builtin/hash-object.c
+++ w/builtin/hash-object.c
@@ -117,7 +117,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
prefix = setup_git_directory_gently(&nongit);
if (vpath && prefix)
- vpath = xstrdup(prefix_filename(prefix, vpath));
+ vpath = prefix_filename(prefix, vpath);
git_config(git_default_config, NULL);
next reply other threads:[~2021-09-07 22:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-07 22:10 Junio C Hamano [this message]
2021-09-08 9:42 ` [PATCH] hash-object: prefix_filename() returns allocated memory these days Jeff King
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=xmqqsfyg82b5.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 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).