Skip to content

Commit 15a4205

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 36d2419 commit 15a4205

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

builtin/name-rev.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ static void name_rev(struct commit *start_commit,
121121

122122
if (deref)
123123
tip_name = to_free = xstrfmt("%s^0", tip_name);
124+
else
125+
tip_name = to_free = xstrdup(tip_name);
124126

125127
if (!create_or_update_name(start_commit, tip_name, taggerdate, 0, 0,
126128
from_tag)) {
@@ -323,7 +325,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
323325
if (taggerdate == TIME_MAX)
324326
taggerdate = commit->date;
325327
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);
327329
}
328330
return 0;
329331
}

0 commit comments

Comments
 (0)