Skip to content

Commit 21a9002

Browse files
committed
Merge branch 'js/exec-path-coverity-workaround' into maint
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
2 parents 2ae2362 + 007ac54 commit 21a9002

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

exec_cmd.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,19 @@ void git_set_argv_exec_path(const char *exec_path)
6464
/* Returns the highest-priority, location to look for git programs. */
6565
const char *git_exec_path(void)
6666
{
67-
const char *env;
67+
static char *cached_exec_path;
6868

6969
if (argv_exec_path)
7070
return argv_exec_path;
7171

72-
env = getenv(EXEC_PATH_ENVIRONMENT);
73-
if (env && *env) {
74-
return env;
72+
if (!cached_exec_path) {
73+
const char *env = getenv(EXEC_PATH_ENVIRONMENT);
74+
if (env && *env)
75+
cached_exec_path = xstrdup(env);
76+
else
77+
cached_exec_path = system_path(GIT_EXEC_PATH);
7578
}
76-
77-
return system_path(GIT_EXEC_PATH);
79+
return cached_exec_path;
7880
}
7981

8082
static void add_path(struct strbuf *out, const char *path)

0 commit comments

Comments
 (0)