repository: free fields before overwriting them
commitf9b7573f6b0039d298de826e22c636db79b9c919
authorJeff King <peff@peff.net>
Tue, 5 Sep 2017 13:04:57 +0000 (5 09:04 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Sep 2017 09:06:26 +0000 (6 18:06 +0900)
tree6335edf95b890d8e4a744e132e2f30a9b5e0df87
parentafbb8838b7d4d1887da1e1871f8e9ccd01ae1138
repository: free fields before overwriting them

It's possible that the repository data may be initialized
twice (e.g., after doing a chdir() to the top of the
worktree we may have to adjust a relative git_dir path). We
should free() any existing fields before assigning to them
to avoid leaks.

This should be safe, as the fields are set based on the
environment or on other strings like the gitdir or
commondir. That makes it impossible that we are feeding an
alias to the just-freed string.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
environment.c
repository.c