path: root/builtin/name-rev.c
diff options
authorRené Scharfe <>2020-02-04 21:17:02 (GMT)
committerJunio C Hamano <>2020-02-05 18:24:15 (GMT)
commit15a4205d967111856279993b8aca24d4ffae787b (patch)
tree27fe344ca829cc6fa8968f5531f9938c184e2c9d /builtin/name-rev.c
parent36d2419c9a1b38f6883318f2af9b704d5d78356f (diff)
name-rev: don't leak path copy in name_ref()
name_ref() duplicates the path string and passes it to name_rev(), which either puts it into a commit slab or ignores it if there is already a better name, leaking it. Move the duplication to name_rev() and release the copy in the latter case. Signed-off-by: René Scharfe <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/name-rev.c')
1 files changed, 3 insertions, 1 deletions
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 2e6820b..3e22a05 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -121,6 +121,8 @@ static void name_rev(struct commit *start_commit,
if (deref)
tip_name = to_free = xstrfmt("%s^0", tip_name);
+ else
+ tip_name = to_free = xstrdup(tip_name);
if (!create_or_update_name(start_commit, tip_name, taggerdate, 0, 0,
from_tag)) {
@@ -323,7 +325,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
if (taggerdate == TIME_MAX)
taggerdate = commit->date;
path = name_ref_abbrev(path, can_abbreviate_output);
- name_rev(commit, xstrdup(path), taggerdate, from_tag, deref);
+ name_rev(commit, path, taggerdate, from_tag, deref);
return 0;