Skip to content

Commit 9e7d8a9

Browse files
szedergitster
authored andcommitted
blame: fix memory corruption scrambling revision name in error message
When attempting to blame a non-existing path, git should show an error message like this: $ git blame e83c516 -- nonexisting-file fatal: no such path nonexisting-file in e83c516 Since the recent commit 835c49f (blame: rework methods that determine 'final' commit, 2017-05-24) the revision name is either missing or some scrambled characters are shown instead. The reason is that the revision name must be duplicated, because it is invalidated when the pending objects array is cleared in the meantime, but this commit dropped the duplication. Restore the duplication of the revision name in the affected functions (find_single_final() and find_single_initial()). Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bd481de commit 9e7d8a9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

blame.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ static struct commit *find_single_final(struct rev_info *revs,
16641664
name = revs->pending.objects[i].name;
16651665
}
16661666
if (name_p)
1667-
*name_p = name;
1667+
*name_p = xstrdup_or_null(name);
16681668
return found;
16691669
}
16701670

@@ -1736,7 +1736,7 @@ static struct commit *find_single_initial(struct rev_info *revs,
17361736
die("No commit to dig up from?");
17371737

17381738
if (name_p)
1739-
*name_p = name;
1739+
*name_p = xstrdup(name);
17401740
return found;
17411741
}
17421742

@@ -1844,6 +1844,8 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
18441844

18451845
if (orig)
18461846
*orig = o;
1847+
1848+
free((char *)final_commit_name);
18471849
}
18481850

18491851

0 commit comments

Comments
 (0)