Re: [PATCH 3/6] revert: add --ff option to allow fast forward when cherry-picking

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

 



Junio C Hamano wrote:

> diff --git a/builtin-revert.c b/builtin-revert.c
> index eff5268..bfe75c8 100644
> --- a/builtin-revert.c
> +++ b/builtin-revert.c
> @@ -314,6 +346,10 @@ static int revert_or_cherry_pick(int argc, const char **argv)
>  	else
>  		parent = commit->parents->item;
>  
> +	if (action == CHERRY_PICK && allow_ff
> +	    && !hashcmp(parent->object.sha1, head))
> +		return fast_forward_to(commit->object.sha1, head);
> +
>  	if (!(message = commit->buffer))
>  		die ("Cannot get commit message for %s",
>  				sha1_to_hex(commit->object.sha1));

Here’s a small fix to go on top.

-- %< --
Subject: revert: fix tiny memory leak in cherry-pick --ff

We forgot to free defmsg when returning early for a fast-forward.

Fixing this should reduce noise during test suite runs with valgrind.
More importantly, once cherry-pick learns to pick multiple commits,
the amount of memory leaked would start to add up.

Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
 builtin-revert.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/builtin-revert.c b/builtin-revert.c
index 476f41e..9a3c14c 100644
--- a/builtin-revert.c
+++ b/builtin-revert.c
@@ -274,7 +274,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)
 	int i, index_fd, clean;
 	char *oneline, *reencoded_message = NULL;
 	const char *message, *encoding;
-	char *defmsg = git_pathdup("MERGE_MSG");
+	char *defmsg = NULL;
 	struct merge_options o;
 	struct tree *result, *next_tree, *base_tree, *head_tree;
 	static struct lock_file index_lock;
@@ -364,6 +364,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)
 	 * reverse of it if we are revert.
 	 */
 
+	defmsg = git_pathdup("MERGE_MSG");
 	msg_fd = hold_lock_file_for_update(&msg_file, defmsg,
 					   LOCK_DIE_ON_ERROR);
 
-- 
1.7.0.2

--
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]