From: Jeff King <peff@peff.net>
To: Stefan Beller <sbeller@google.com>
Cc: git@vger.kernel.org, gitster@pobox.com, sunshine@sunshineco.com
Subject: Re: [PATCH] prefix_path(): Unconditionally free result of prefix_path
Date: Mon, 4 May 2015 23:21:59 -0400 [thread overview]
Message-ID: <20150505032158.GA23587@peff.net> (raw)
In-Reply-To: <1430766714-22368-1-git-send-email-sbeller@google.com>
On Mon, May 04, 2015 at 12:11:54PM -0700, Stefan Beller wrote:
> prefix_path() always returns a newly allocated string since
> d089eba (setup: sanitize absolute and funny paths in get_pathspec(),
> 2008-01-28)
>
> Additionally the const is dropped from the pointers, so the call to
> free doesn't need a cast.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>
> Notes:
> Thanks for all the suggestions!
> They are incorporated into this version of the patch.
>
> builtin/checkout-index.c | 10 ++++------
> builtin/update-index.c | 5 ++---
> 2 files changed, 6 insertions(+), 9 deletions(-)
Should we also squash in these sites? I think they are adequately
covered under the proposed log message.
Found by grepping for prefix_path calls. The only remainders are:
1. in blame, we assign the result to a const char that may also point
straight into to argv, but we never actually free either way
2. test-path-utils does not free at all, but we probably don't care
either way
diff --git a/builtin/update-index.c b/builtin/update-index.c
index a92eed2..0665b31 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -870,14 +870,14 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
case PARSE_OPT_DONE:
{
const char *path = ctx.argv[0];
- const char *p;
+ char *p;
setup_work_tree();
p = prefix_path(prefix, prefix_length, path);
update_one(p);
if (set_executable_bit)
chmod_path(set_executable_bit, p);
- free((char *)p);
+ free(p);
ctx.argc--;
ctx.argv++;
break;
@@ -908,7 +908,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
setup_work_tree();
while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
- const char *p;
+ char *p;
if (line_termination && buf.buf[0] == '"') {
strbuf_reset(&nbuf);
if (unquote_c_style(&nbuf, buf.buf, NULL))
@@ -919,7 +919,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
update_one(p);
if (set_executable_bit)
chmod_path(set_executable_bit, p);
- free((char *)p);
+ free(p);
}
strbuf_release(&nbuf);
strbuf_release(&buf);
next prev parent reply other threads:[~2015-05-05 3:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-04 19:11 [PATCH] prefix_path(): Unconditionally free result of prefix_path Stefan Beller
2015-05-04 20:19 ` Eric Sunshine
2015-05-04 22:29 ` Junio C Hamano
2015-05-05 3:21 ` Jeff King [this message]
2015-05-05 16:28 ` Stefan Beller
2015-05-05 17:36 ` Junio C Hamano
2015-05-05 17:56 ` Jeff King
2015-05-05 18:09 ` Junio C Hamano
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=20150505032158.GA23587@peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sbeller@google.com \
--cc=sunshine@sunshineco.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).