setup_discovered_git_dir(): plug memory leak
The setup_explicit_git_dir() function does not take custody of the string passed as first parameter; we have to release it if we turned the value of git_dir into an absolute path. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
May 4, 2017 at 15:56 UTC
2d4dcf210e156153a9c1b11bc60d647d5a327624
1 file changed
+7
-2
setup.c
+7
-2
@@ -703,11 +703,16 @@ static const char *setup_discovered_git_dir(const char *gitdir,
703
704
/* --work-tree is set without --git-dir; use discovered one */
705
if (getenv(GIT_WORK_TREE_ENVIRONMENT) || git_work_tree_cfg) {
706
+ char *to_free = NULL;
707
+ const char *ret;
708
+
709
if (offset != cwd->len && !is_absolute_path(gitdir))
707
- gitdir = real_pathdup(gitdir, 1);
710
+ gitdir = to_free = real_pathdup(gitdir, 1);
711
if (chdir(cwd->buf))
712
die_errno("Could not come back to cwd");
710
- return setup_explicit_git_dir(gitdir, cwd, nongit_ok);
713
+ ret = setup_explicit_git_dir(gitdir, cwd, nongit_ok);
714
+ free(to_free);
715
+ return ret;
716
}
717
718
/* #16.2, #17.2, #20.2, #21.2, #24, #25, #28, #29 (see t1510) */