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

[PATCH 3/4] sequencer: free memory used in "make_patch" function

From
Christian Couder <chriscool@tuxfamily.org>
Date
Jun 26, 2009, 21:08 UTC
Message-ID
<20090626210847.3885.22240.chriscool@tuxfamily.org>
In-Reply-To
<20090626205319.3885.91532.chriscool@tuxfamily.org>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin-sequencer--helper.c |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/builtin-sequencer--helper.c b/builtin-sequencer--helper.c
index 8d32480..1dda525 100644
--- a/builtin-sequencer--helper.c
+++ b/builtin-sequencer--helper.c
@@ -18,6 +18,7 @@ static void make_patch(struct commit *commit)
 	struct commit_list *parents = commit->parents;
 	const char **args;
 	struct child_process chld;
+	int i;
 	int fd = open(PATCH_FILE, O_WRONLY | O_CREAT, 0666);
 	if (fd < 0)
 		return;
@@ -34,20 +35,22 @@ static void make_patch(struct commit *commit)
 		args[2] = xstrdup(sha1_to_hex(parents->item->object.sha1));
 		args[3] = xstrdup(sha1_to_hex(((struct object *)commit)->sha1));
 	} else {
-		int i = 0;
 		int count = 1;
 
 		for (; parents; parents = parents->next)
 			++count;
+
+		i = 0;
 		args = xcalloc(count + 3, sizeof(char *));
 		args[i++] = "diff";
 		args[i++] = "--cc";
 		args[i++] = xstrdup(sha1_to_hex(commit->object.sha1));
 
 		for (parents = commit->parents; parents;
-		     parents = parents->next)
-			args[i++] = xstrdup(sha1_to_hex(
-					    parents->item->object.sha1));
+		     parents = parents->next) {
+			char *hex = sha1_to_hex(parents->item->object.sha1);
+			args[i++] = xstrdup(hex);
+		}
 	}
 
 	chld.argv = args;
@@ -55,11 +58,12 @@ static void make_patch(struct commit *commit)
 	chld.out = fd;
 
 	/* Run, ignore errors. */
-	if (start_command(&chld))
-		return;
-	finish_command(&chld);
+	if (!start_command(&chld))
+		finish_command(&chld);
 
-	/* TODO: free dup'ed SHAs in argument list */
+	for (i = 2; args[i]; i++)
+		free((char *)args[i]);
+	free(args);
 }
 
 /* Return a commit object of "arg" */
-- 
1.6.3.GIT
Previous: Christian CouderNext: Christian Couder
Message 5 of 6 in “start using sequencer code to port "rebase -i"”
  1. 0/4 start using sequencer code to port "rebase -i"Christian Couder, Jun 26, 2009
  2. 1/4 sequencer: add "builtin-sequencer--helper.c"Christian Couder, Jun 26, 2009
  3. 2/4 sequencer: add "make_patch" function to save a patchChristian Couder, Jun 26, 2009
  4. Christian CouderJun 28, 2009
  5. 3/4 sequencer: free memory used in "make_patch" functionChristian Couder, Jun 26, 2009
  6. 4/4 rebase -i: use "git sequencer--helper --make-patch"Christian Couder, Jun 26, 2009

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.