[PATCH v4 13/25] setup_bare_git_dir(): help static analysis
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- May 4, 2017, 13:56 UTC
- Message-ID
- <fc054bdc7754045b01655feee88a74203bdf128c.1493906085.git.johannes.schindelin@gmx.de>
- In-Reply-To
- <cover.1493906084.git.johannes.schindelin@gmx.de>
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> --- setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/setup.c b/setup.c index 0309c278218..0320a9ad14c 100644 --- 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))
-- 2.12.2.windows.2.800.gede8f145e06