@matheusbsbs / matheus-bagliano / commits / 15a4205d96
Fork 0

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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Feb 4, 2020 at 22:17 UTC 15a4205d967111856279993b8aca24d4ffae787b
1 file changed +3 -1
builtin/name-rev.c
+3 -1
@@ -121,6 +121,8 @@ static void name_rev(struct commit *start_commit,
121
122 if (deref)
123 tip_name = to_free = xstrfmt("%s^0", tip_name);
124 + else
125 + tip_name = to_free = xstrdup(tip_name);
126
127 if (!create_or_update_name(start_commit, tip_name, taggerdate, 0, 0,
128 from_tag)) {
@@ -323,7 +325,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
325 if (taggerdate == TIME_MAX)
326 taggerdate = commit->date;
327 path = name_ref_abbrev(path, can_abbreviate_output);
326 - name_rev(commit, xstrdup(path), taggerdate, from_tag, deref);
328 + name_rev(commit, path, taggerdate, from_tag, deref);
329 }
330 return 0;
331 }