On Tue, Feb 27, 2018 at 1:57 AM, Eric Sunshine [off-list ref] wrote:
Can:
char *old_gitdir = repo->gitdir;
repo->gitdir = xstrdup(...);
free(old_gitdir);
be simplified to:
free(repo->gitdir);
repo->gitdir = xstrdup(...);
?
No because I think "root" (not quoted here) could point to the same
value as repo->gitdir, if you free that first, the second xstrdup()
will duplicate a freed memory. See 1fb2b636c6 (set_git_dir: handle
feeding gitdir to itself - 2017-09-05)
I will add a comment about this since it's not very clear from this code.
--
Duy