aboutsummaryrefslogtreecommitdiff
path: root/exec_cmd.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-01-31 13:14:57 -0800
committerJunio C Hamano <gitster@pobox.com>2017-01-31 13:14:57 -0800
commite8272fd5fbb4f3a6d264fe0721247efe08aada8f (patch)
tree7daf9cd8de9973de749dc7b42189d049596b8388 /exec_cmd.c
parent792e22e3fd99f204be11b0ff173f2d991308dca5 (diff)
parent007ac544011213045e3905983b4350ffec8f41f7 (diff)
downloadgit-e8272fd5fbb4f3a6d264fe0721247efe08aada8f.tar.gz
git-e8272fd5fbb4f3a6d264fe0721247efe08aada8f.tar.xz
Merge branch 'js/exec-path-coverity-workaround'
Code cleanup. * js/exec-path-coverity-workaround: git_exec_path: do not return the result of getenv() git_exec_path: avoid Coverity warning about unfree()d result
Diffstat (limited to 'exec_cmd.c')
-rw-r--r--exec_cmd.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/exec_cmd.c b/exec_cmd.c
index 19ac2146d..fb94aeba9 100644
--- a/exec_cmd.c
+++ b/exec_cmd.c
@@ -64,17 +64,19 @@ void git_set_argv_exec_path(const char *exec_path)
/* Returns the highest-priority, location to look for git programs. */
const char *git_exec_path(void)
{
- const char *env;
+ static char *cached_exec_path;
if (argv_exec_path)
return argv_exec_path;
- env = getenv(EXEC_PATH_ENVIRONMENT);
- if (env && *env) {
- return env;
+ if (!cached_exec_path) {
+ const char *env = getenv(EXEC_PATH_ENVIRONMENT);
+ if (env && *env)
+ cached_exec_path = xstrdup(env);
+ else
+ cached_exec_path = system_path(GIT_EXEC_PATH);
}
-
- return system_path(GIT_EXEC_PATH);
+ return cached_exec_path;
}
static void add_path(struct strbuf *out, const char *path)