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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx>
---
 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


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]