git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] prefix_path(): Unconditionally free result of prefix_path

From
Jeff King <peff@peff.net>
Date
May 5, 2015, 03:21 UTC
Message-ID
<20150505032158.GA23587@peff.net>
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:
Show 17 quoted lines
> 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);
Previous: Junio C HamanoNext: Stefan Beller
Message 4 of 8 in “prefix_path(): Unconditionally free result of prefix_path”
  1. prefix_path(): Unconditionally free result of prefix_pathStefan Beller, May 4, 2015
  2. Eric SunshineMay 4, 2015
  3. Junio C HamanoMay 4, 2015
  4. Jeff KingMay 5, 2015
  5. Stefan BellerMay 5, 2015
  6. Junio C HamanoMay 5, 2015
  7. Jeff KingMay 5, 2015
  8. Junio C HamanoMay 5, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.