Skip to content

Commit

Permalink
name-rev: don't leak path copy in name_ref()
Browse files Browse the repository at this point in the history
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 <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
rscharfe authored and gitster committed Feb 5, 2020
1 parent 36d2419 commit 15a4205
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion builtin/name-rev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 15a4205

Please sign in to comment.