Skip to content

Commit 2d4dcf2

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent da6f847 commit 2d4dcf2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

setup.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,11 +703,16 @@ static const char *setup_discovered_git_dir(const char *gitdir,
703703

704704
/* --work-tree is set without --git-dir; use discovered one */
705705
if (getenv(GIT_WORK_TREE_ENVIRONMENT) || git_work_tree_cfg) {
706+
char *to_free = NULL;
707+
const char *ret;
708+
706709
if (offset != cwd->len && !is_absolute_path(gitdir))
707-
gitdir = real_pathdup(gitdir, 1);
710+
gitdir = to_free = real_pathdup(gitdir, 1);
708711
if (chdir(cwd->buf))
709712
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;
711716
}
712717

713718
/* #16.2, #17.2, #20.2, #21.2, #24, #25, #28, #29 (see t1510) */

0 commit comments

Comments
 (0)