OSDN Git Service

setup_bare_git_dir(): help static analysis
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 4 May 2017 13:56:47 +0000 (15:56 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 May 2017 03:18:19 +0000 (12:18 +0900)
Coverity reported a memory leak in this function. However, it can only
be called once, as setup_git_directory() changes global state and hence
is not reentrant.

Mark the variable as static to indicate that this is a singleton.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
setup.c

diff --git a/setup.c b/setup.c
index 0309c27..0320a9a 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -748,7 +748,7 @@ static const char *setup_bare_git_dir(struct strbuf *cwd, int offset,
 
        /* --work-tree is set without --git-dir; use discovered one */
        if (getenv(GIT_WORK_TREE_ENVIRONMENT) || git_work_tree_cfg) {
-               const char *gitdir;
+               static const char *gitdir;
 
                gitdir = offset == cwd->len ? "." : xmemdupz(cwd->buf, offset);
                if (chdir(cwd->buf))