summaryrefslogtreecommitdiff
path: root/builtin/worktree.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-09-05 13:05:01 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-09-06 09:06:26 (GMT)
commit1fb2b636c672fea06fdc5f50d5c0ed44117ae45a (patch)
tree5569c294402e712b73b4e4743d3bc9518a75a3ca /builtin/worktree.c
parentf9b7573f6b0039d298de826e22c636db79b9c919 (diff)
downloadgit-1fb2b636c672fea06fdc5f50d5c0ed44117ae45a.zip
git-1fb2b636c672fea06fdc5f50d5c0ed44117ae45a.tar.gz
git-1fb2b636c672fea06fdc5f50d5c0ed44117ae45a.tar.bz2
set_git_dir: handle feeding gitdir to itself
Ideally we'd free the existing gitdir field before assigning the new one, to avoid a memory leak. But we can't do so safely because some callers do the equivalent of: set_git_dir(get_git_dir()); We can detect that case as a noop, but there are even more complicated cases like: set_git_dir(remove_leading_path(worktree, get_git_dir()); where we really do need to do some work, but the original string must remain valid. Rather than put the burden on callers to make a copy of the string (only to free it later, since we'll make a copy of it ourselves), let's solve the problem inside set_git_dir(). We can make a copy of the pointer for the old gitdir, and then avoid freeing it until after we've made our new copy. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/worktree.c')
0 files changed, 0 insertions, 0 deletions