]> git.ipfire.org Git - thirdparty/git.git/commitdiff
name-rev: don't leak path copy in name_ref()
authorRené Scharfe <l.s.r@web.de>
Tue, 4 Feb 2020 21:17:02 +0000 (22:17 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 5 Feb 2020 18:24:15 +0000 (10:24 -0800)
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>
builtin/name-rev.c

index 2e6820bd5b92c08c112100f2d4c2e6f602f516e5..3e22a0503eb69d820e2955d2608b8d42f9d15ca4 100644 (file)
@@ -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;
 }