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

[PATCH 4/5] Call git_pathdup() rather than xstrdup(git_path("..."))

From
Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Date
Sep 4, 2012, 17:30 UTC
Message-ID
<50463AAD.7060107@ramsay1.demon.co.uk>

In addition to updating the two xstrdup(git_path("...")) call sites with git_pathdup(), we also fix a memory leak by freeing the memory allocated to the ADD_EDIT.patch 'file' in the edit_patch() function.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
 bisect.c      | 2 +-
 builtin/add.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/bisect.c b/bisect.c
index 48acf73..1aad49b 100644
--- a/bisect.c
+++ b/bisect.c
@@ -833,7 +833,7 @@ static int check_ancestors(const char *prefix)
  */
 static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
 {
-	char *filename = xstrdup(git_path("BISECT_ANCESTORS_OK"));
+	char *filename = git_pathdup("BISECT_ANCESTORS_OK");
 	struct stat st;
 	int fd;
 
diff --git a/builtin/add.c b/builtin/add.c
index 89dce56..2fc2677 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -260,7 +260,7 @@ int interactive_add(int argc, const char **argv, const char *prefix, int patch)
 
 static int edit_patch(int argc, const char **argv, const char *prefix)
 {
-	char *file = xstrdup(git_path("ADD_EDIT.patch"));
+	char *file = git_pathdup("ADD_EDIT.patch");
 	const char *apply_argv[] = { "apply", "--recount", "--cached",
 		NULL, NULL };
 	struct child_process child;
@@ -303,6 +303,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
 		die (_("Could not apply '%s'"), file);
 
 	unlink(file);
+	free(file);
 	return 0;
 }
 
-- 
1.7.12
Message 1 of 1 in “Call git_pathdup() rather than xstrdup(git_path("..."))”
  1. 4/5 Call git_pathdup() rather than xstrdup(git_path("..."))Ramsay Jones, Sep 4, 2012

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.